Skip to content

Commit

Permalink
Merge pull request #2 from Dubhe-Studio/1.20.1-dev
Browse files Browse the repository at this point in the history
update to 1.20.1
  • Loading branch information
Gu-ZT authored Aug 1, 2023
2 parents 85bfa5f + 50487a8 commit 264ac04
Show file tree
Hide file tree
Showing 44 changed files with 392 additions and 345 deletions.
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ minecraft {
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
maven { url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' }
maven {
name = 'GeckoLib'
url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/'
}
}

dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
annotationProcessor 'org.spongepowered:mixin:0.8.4:processor'
implementation fg.deobf("software.bernie.geckolib:geckolib-1.18-forge:${geckolib_verison}")
implementation fg.deobf("software.bernie.geckolib:geckolib-forge-1.20:${geckolib_verison}")
}

jar {
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ maven_group = dev.dubhe
mod_version = 0.0.1

channel=parchment
channel_version=2022.03.13-1.18.2
mc_version=1.18.2
forge_version=40.1.0
geckolib_verison=3.0.15
#channel=official
channel_version=2023.07.16-1.20.1
mc_version=1.20.1
forge_version=47.0.19
geckolib_verison=4.2

build_number = undefined
19 changes: 18 additions & 1 deletion src/main/java/dev/dubhe/torchikoma/Torchikoma.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package dev.dubhe.torchikoma;

import dev.dubhe.torchikoma.entity.TorchikomaEntity;
import dev.dubhe.torchikoma.network.C2STorchikomaEntityShoot;
import dev.dubhe.torchikoma.network.Network;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -11,7 +19,16 @@ public class Torchikoma {
public static final String ID = "torchikoma";

public Torchikoma() {
LOGGER.info("test");
MinecraftForge.EVENT_BUS.addListener(Torchikoma::onPlayerRightClick);
}

@SubscribeEvent
public static void onPlayerRightClick(PlayerInteractEvent.RightClickEmpty event) {
Player player = event.getEntity();
Entity vehicle = player.getVehicle();
if (vehicle instanceof TorchikomaEntity) {
Network.sendToServer(new C2STorchikomaEntityShoot(player.getUUID()));
}
}

public static ResourceLocation of(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public InteractionResult use(@Nonnull BlockState pState, @Nonnull Level pLevel,
}

private static void explode(Level pLevel, BlockPos pPos, @Nullable LivingEntity pEntity) {
pLevel.gameEvent(GameEvent.EXPLODE, pPos);
pLevel.gameEvent(null, GameEvent.EXPLODE, pPos);
if (!pLevel.isClientSide) {
pLevel.playSound(null, pPos.getX(), pPos.getY(), pPos.getZ(), SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
BlockPos behindBlock = behindBlock(pLevel, pPos);
Expand All @@ -153,7 +153,7 @@ public void onProjectileHit(Level pLevel, @Nonnull BlockState pState, @Nonnull B
BlockPos blockpos = pHit.getBlockPos();
Entity entity = pProjectile.getOwner();
if (pProjectile.isOnFire() && pProjectile.mayInteract(pLevel, blockpos)) {
onCaughtFire(pState, pLevel, blockpos, null, entity instanceof LivingEntity ? (LivingEntity)entity : null);
onCaughtFire(pState, pLevel, blockpos, null, entity instanceof LivingEntity ? (LivingEntity) entity : null);
pLevel.removeBlock(blockpos, false);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/dev/dubhe/torchikoma/block/ComponentBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.util.RandomSource;
import net.minecraft.world.damagesource.DamageSources;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.context.BlockPlaceContext;
Expand All @@ -23,7 +23,6 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Random;

public class ComponentBlock extends HorizontalDirectionalBlock implements SimpleWaterloggedBlock {
public static final BooleanProperty LIT = RedstoneTorchBlock.LIT;
Expand Down Expand Up @@ -80,7 +79,7 @@ public boolean canSurvive(@Nonnull BlockState pState, @Nonnull LevelReader pLeve
}

@Override
public void tick(BlockState pState, @Nonnull ServerLevel pLevel, @Nonnull BlockPos pPos, @Nonnull Random pRand) {
public void animateTick(BlockState pState, @Nonnull Level pLevel, @Nonnull BlockPos pPos, @Nonnull RandomSource pRand) {
if (pState.getValue(LIT) && !pLevel.hasNeighborSignal(pPos)) {
pLevel.setBlock(pPos, pState.cycle(LIT), 2);
}
Expand All @@ -103,7 +102,7 @@ public void neighborChanged(@Nonnull BlockState pState, Level pLevel, @Nonnull B
@Override
public void stepOn(@Nonnull Level pLevel, @Nonnull BlockPos pPos,BlockState pState, @Nonnull Entity pEntity) {
if (pState.getValue(LIT) && pEntity instanceof LivingEntity) {
pEntity.hurt(DamageSource.GENERIC, (float)this.damage);
pEntity.hurt(new DamageSources(pLevel.registryAccess()).generic(), (float)this.damage);
}
super.stepOn(pLevel, pPos, pState, pEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Pla
if (!pLevel.isClientSide) {
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
if (blockentity instanceof TorchikomaBlockEntity torchikomaBlockEntity) {
NetworkHooks.openGui((ServerPlayer) pPlayer, this.getMenu(
NetworkHooks.openScreen((ServerPlayer) pPlayer, this.getMenu(
torchikomaBlockEntity.getDisplayName(),
(id, inv, player) -> new TorchikomaBlockMenu(id, inv, torchikomaBlockEntity)
), buffer -> buffer.writeBlockPos(pPos));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
Expand All @@ -22,8 +21,8 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;

Expand Down Expand Up @@ -151,7 +150,7 @@ public void setCustomName(Component pName) {
}

public Component getName() {
return this.name != null ? this.name : new TranslatableComponent("torchikoma.title");
return this.name != null ? this.name : Component.translatable("torchikoma.title");
}

public Component getDisplayName() {
Expand Down Expand Up @@ -218,7 +217,7 @@ protected IItemHandler createUnSidedHandler() {
}

public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable Direction side) {
if (!this.remove && cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
if (!this.remove && cap == ForgeCapabilities.ITEM_HANDLER)
return itemHandler.cast();
return super.getCapability(cap, side);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ protected void onHitBlock(@Nonnull BlockHitResult result) {
entity3.setDeltaMovement(0,i,i);
entity4.setDeltaMovement(0,i,-i);

level.addFreshEntity(entity1);
level.addFreshEntity(entity2);
level.addFreshEntity(entity3);
level.addFreshEntity(entity4);
level().addFreshEntity(entity1);
level().addFreshEntity(entity2);
level().addFreshEntity(entity3);
level().addFreshEntity(entity4);

this.level.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
this.level().playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 1.0F, 1.0F);
this.discard();
}
}
35 changes: 19 additions & 16 deletions src/main/java/dev/dubhe/torchikoma/entity/TorchEntity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.dubhe.torchikoma.entity;

import dev.dubhe.torchikoma.mixin.DamageSourcesAccessor;
import dev.dubhe.torchikoma.registry.MyEntities;
import dev.dubhe.torchikoma.registry.MyItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
Expand All @@ -18,7 +20,6 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.IndirectEntityDamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -74,7 +75,7 @@ public TorchEntity(LivingEntity entity, ItemStack stack) {
}

public TorchEntity(EntityType<? extends TorchEntity> entityType, LivingEntity entity, ItemStack stack) {
super(entityType, entity.level);
super(entityType, entity.level());
this.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
this.setOwner(entity);
this.entityData.set(ITEM_STACK, stack);
Expand Down Expand Up @@ -111,7 +112,7 @@ public void readAdditionalSaveData(CompoundTag pCompound) {
super.readAdditionalSaveData(pCompound);
this.life = pCompound.getShort("life");
if (pCompound.contains("inBlockState", 10)) {
this.lastState = NbtUtils.readBlockState(pCompound.getCompound("inBlockState"));
this.lastState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), pCompound.getCompound("inBlockState"));
}
this.shakeTime = pCompound.getByte("shake") & 255;
this.inGround = pCompound.getBoolean("inGround");
Expand All @@ -137,9 +138,9 @@ public void tick() {
}

BlockPos blockpos = this.blockPosition();
BlockState blockstate = this.level.getBlockState(blockpos);
BlockState blockstate = this.level().getBlockState(blockpos);
if (!blockstate.isAir()) {
VoxelShape voxelshape = blockstate.getCollisionShape(this.level, blockpos);
VoxelShape voxelshape = blockstate.getCollisionShape(this.level(), blockpos);
if (!voxelshape.isEmpty()) {
Vec3 pos = this.position();
for(AABB aabb : voxelshape.toAabbs()) {
Expand All @@ -154,13 +155,13 @@ public void tick() {
if (this.isInWaterOrRain() || blockstate.is(Blocks.POWDER_SNOW)) this.clearFire();
if (this.inGround) {
if (this.lastState != blockstate && this.shouldFall()) this.startFalling();
else if (!this.level.isClientSide && ++this.life >= 1200) this.discard();
else if (!this.level().isClientSide && ++this.life >= 1200) this.discard();
++this.inGroundTime;
} else {
this.inGroundTime = 0;
Vec3 oPos = this.position();
Vec3 nPos = oPos.add(moveResult);
HitResult hit = this.level.clip(new ClipContext(oPos, nPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this));
HitResult hit = this.level().clip(new ClipContext(oPos, nPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this));
if (hit.getType() != HitResult.Type.MISS) nPos = hit.getLocation();
while(!this.isRemoved()) {
EntityHitResult entityHit = this.findHitEntity(oPos, nPos);
Expand Down Expand Up @@ -196,7 +197,7 @@ public void tick() {
float f = 0.99F;
if (this.isInWater()) {
for(int j = 0; j < 4; ++j) {
this.level.addParticle(ParticleTypes.BUBBLE, nX - oX * 0.25D, nY - oY * 0.25D, nZ - oZ * 0.25D, oX, oY, oZ);
this.level().addParticle(ParticleTypes.BUBBLE, nX - oX * 0.25D, nY - oY * 0.25D, nZ - oZ * 0.25D, oX, oY, oZ);
}
if (this.slowInWater()) f = 0.6F;
}
Expand All @@ -211,7 +212,7 @@ public void tick() {
}

private boolean shouldFall() {
return this.inGround && this.level.noCollision((new AABB(this.position(), this.position())).inflate(0.06D));
return this.inGround && this.level().noCollision((new AABB(this.position(), this.position())).inflate(0.06D));
}

private void startFalling() {
Expand Down Expand Up @@ -249,7 +250,7 @@ protected void onHitEntity(EntityHitResult pResult) {
if (hitEntity.hurt(damagesource, (float) this.baseDamage)) {
if (hitEnderman) return;
if (hitEntity instanceof LivingEntity livingentity) {
if (!this.level.isClientSide && owner instanceof LivingEntity) {
if (!this.level().isClientSide && owner instanceof LivingEntity) {
EnchantmentHelper.doPostHurtEffects(livingentity, owner);
EnchantmentHelper.doPostDamageEffects((LivingEntity)owner, livingentity);
}
Expand All @@ -265,7 +266,7 @@ protected void onHitEntity(EntityHitResult pResult) {
this.setYRot(this.getYRot() + 180.0F);
this.yRotO += 180.0F;
double sqr = this.getDeltaMovement().lengthSqr();
if (this.level.isClientSide) {
if (this.level().isClientSide) {
if (sqr == 0.0D) this.discard();
} else if (sqr < 1.0E-7D) {
if (this.pickup == Pickup.ALLOWED) {
Expand All @@ -287,12 +288,14 @@ public void setRemainingFireTicks(int pTicks) {
}

private DamageSource getDamageSource(@Nullable Entity entity) {
return (new IndirectEntityDamageSource("torch", this, entity)).setProjectile();
// return (new IndirectEntityDamageSource("torch", this, entity)).setProjectile(); // FIXME
// return ((DamageSourcesAccessor) entity.damageSources()).callSource();
return entity.damageSources().generic(); // TODO: 替换掉这个通用伤害源
}

@Override
protected void onHitBlock(@Nonnull BlockHitResult result) {
this.lastState = this.level.getBlockState(result.getBlockPos());
this.lastState = this.level().getBlockState(result.getBlockPos());
super.onHitBlock(result);
Vec3 offset = result.getLocation().subtract(this.getX(), this.getY(), this.getZ());
this.setDeltaMovement(offset);
Expand All @@ -309,7 +312,7 @@ protected void onHitBlock(@Nonnull BlockHitResult result) {
}

protected EntityHitResult findHitEntity(Vec3 pStartVec, Vec3 pEndVec) {
return ProjectileUtil.getEntityHitResult(this.level, this, pStartVec, pEndVec, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), this::canHitEntity);
return ProjectileUtil.getEntityHitResult(this.level(), this, pStartVec, pEndVec, this.getBoundingBox().expandTowards(this.getDeltaMovement()).inflate(1.0D), this::canHitEntity);
}

@Override
Expand All @@ -322,8 +325,8 @@ public void setOwner(@Nullable Entity pEntity) {

@Override
public void playerTouch(Player pEntity) {
if (!this.level.isClientSide && this.inGround && this.shakeTime <= 0 && this.tryPickup(pEntity)) {
if (!this.isRemoved()) ((ServerLevel)this.level).getChunkSource().broadcast(this, new ClientboundTakeItemEntityPacket(this.getId(), pEntity.getId(), 1));
if (!this.level().isClientSide && this.inGround && this.shakeTime <= 0 && this.tryPickup(pEntity)) {
if (!this.isRemoved()) ((ServerLevel)this.level()).getChunkSource().broadcast(this, new ClientboundTakeItemEntityPacket(this.getId(), pEntity.getId(), 1));
this.discard();
}
}
Expand Down
Loading

0 comments on commit 264ac04

Please sign in to comment.