diff --git a/build.gradle b/build.gradle index 943423d187..c21c8ec735 100644 --- a/build.gradle +++ b/build.gradle @@ -44,10 +44,10 @@ ext { ] } MAPPING_CHANNEL = 'official' - MC_VERSION = '1.20.2-pre4' + MC_VERSION = '1.20.2-rc1' MAPPING_VERSION = MC_VERSION MC_NEXT_VERSION = '1.21' - MCP_VERSION = '20230913.141520' + MCP_VERSION = '20230915.121641' SNAPSHOT = false SPI_VERSION = '7.0.1' diff --git a/patches/minecraft/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java.patch b/patches/minecraft/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java.patch index b4ef4467d4..677da90195 100644 --- a/patches/minecraft/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java.patch +++ b/patches/minecraft/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java +++ b/net/minecraft/client/gui/screens/worldselection/WorldOpenFlows.java -@@ -183,13 +_,23 @@ +@@ -181,13 +_,23 @@ } private void doLoadLevel(Screen p_233146_, String p_233147_, boolean p_233148_, boolean p_233149_) { @@ -24,7 +24,7 @@ } catch (Exception exception) { LOGGER.warn("Failed to load level data or datapacks, can't proceed with server load", (Throwable)exception); if (!p_233148_) { -@@ -209,7 +_,9 @@ +@@ -207,7 +_,9 @@ WorldData worlddata = worldstem.worldData(); boolean flag = worlddata.worldGenOptions().isOldCustomizedWorld(); boolean flag1 = worlddata.worldGenSettingsLifecycle() != Lifecycle.stable(); @@ -35,7 +35,7 @@ this.minecraft.getDownloadedPackSource().loadBundledResourcePack(levelstoragesource$levelstorageaccess).thenApply((p_233177_) -> { return true; }).exceptionallyComposeAsync((p_233183_) -> { -@@ -231,9 +_,11 @@ +@@ -229,9 +_,11 @@ return null; }); } else { diff --git a/patches/minecraft/net/minecraft/core/dispenser/DispenseItemBehavior.java.patch b/patches/minecraft/net/minecraft/core/dispenser/DispenseItemBehavior.java.patch index c650799f7f..550b2fa594 100644 --- a/patches/minecraft/net/minecraft/core/dispenser/DispenseItemBehavior.java.patch +++ b/patches/minecraft/net/minecraft/core/dispenser/DispenseItemBehavior.java.patch @@ -16,8 +16,8 @@ - if (blockstate.getBlock() instanceof TntBlock) { - TntBlock.explode(level, blockpos); - level.removeBlock(blockpos, false); -+ if (blockstate.isFlammable(level, blockpos, p_123412_.getBlockState().getValue(DispenserBlock.FACING).getOpposite())) { -+ blockstate.onCaughtFire(level, blockpos, p_123412_.getBlockState().getValue(DispenserBlock.FACING).getOpposite(), null); ++ if (blockstate.isFlammable(level, blockpos, p_123412_.state().getValue(DispenserBlock.FACING).getOpposite())) { ++ blockstate.onCaughtFire(level, blockpos, p_123412_.state().getValue(DispenserBlock.FACING).getOpposite(), null); + if (blockstate.getBlock() instanceof TntBlock) + level.removeBlock(blockpos, false); } else { diff --git a/patches/minecraft/net/minecraft/nbt/CompoundTag.java.patch b/patches/minecraft/net/minecraft/nbt/CompoundTag.java.patch index 45cc62185c..5f158056c2 100644 --- a/patches/minecraft/net/minecraft/nbt/CompoundTag.java.patch +++ b/patches/minecraft/net/minecraft/nbt/CompoundTag.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/nbt/CompoundTag.java +++ b/net/minecraft/nbt/CompoundTag.java -@@ -210,6 +_,7 @@ +@@ -204,6 +_,7 @@ @Nullable public Tag put(String p_128366_, Tag p_128367_) { diff --git a/patches/minecraft/net/minecraft/nbt/NbtAccounter.java.patch b/patches/minecraft/net/minecraft/nbt/NbtAccounter.java.patch index 0bc5b28b11..f9a0bc7055 100644 --- a/patches/minecraft/net/minecraft/nbt/NbtAccounter.java.patch +++ b/patches/minecraft/net/minecraft/nbt/NbtAccounter.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/nbt/NbtAccounter.java +++ b/net/minecraft/nbt/NbtAccounter.java -@@ -43,6 +_,36 @@ +@@ -50,6 +_,36 @@ } } diff --git a/patches/minecraft/net/minecraft/nbt/NbtIo.java.patch b/patches/minecraft/net/minecraft/nbt/NbtIo.java.patch index 8c839fd297..8c308d134f 100644 --- a/patches/minecraft/net/minecraft/nbt/NbtIo.java.patch +++ b/patches/minecraft/net/minecraft/nbt/NbtIo.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/nbt/NbtIo.java +++ b/net/minecraft/nbt/NbtIo.java -@@ -155,10 +_,12 @@ +@@ -154,10 +_,12 @@ private static Tag readUnnamedTag(DataInput p_128931_, NbtAccounter p_128933_) throws IOException { byte b0 = p_128931_.readByte(); diff --git a/patches/minecraft/net/minecraft/nbt/StringTag.java.patch b/patches/minecraft/net/minecraft/nbt/StringTag.java.patch index 65258fa368..177f389cee 100644 --- a/patches/minecraft/net/minecraft/nbt/StringTag.java.patch +++ b/patches/minecraft/net/minecraft/nbt/StringTag.java.patch @@ -4,7 +4,7 @@ private static String readAccounted(DataInput p_301750_, NbtAccounter p_301732_) throws IOException { p_301732_.accountBytes(36L); String s = p_301750_.readUTF(); -- p_301732_.accountBytes(2L * (long)s.length()); +- p_301732_.accountBytes(2L, (long)s.length()); + p_301732_.readUTF(s); return s; } diff --git a/patches/minecraft/net/minecraft/world/entity/vehicle/AbstractMinecart.java.patch b/patches/minecraft/net/minecraft/world/entity/vehicle/AbstractMinecart.java.patch index 5ba0b6a658..d3a8f38860 100644 --- a/patches/minecraft/net/minecraft/world/entity/vehicle/AbstractMinecart.java.patch +++ b/patches/minecraft/net/minecraft/world/entity/vehicle/AbstractMinecart.java.patch @@ -6,10 +6,10 @@ -public abstract class AbstractMinecart extends Entity { +public abstract class AbstractMinecart extends Entity implements net.minecraftforge.common.extensions.IForgeAbstractMinecart { + private static final float PASSENGER_ATTACHMENT_Y = 0.1875F; private static final EntityDataAccessor DATA_ID_HURT = SynchedEntityData.defineId(AbstractMinecart.class, EntityDataSerializers.INT); private static final EntityDataAccessor DATA_ID_HURTDIR = SynchedEntityData.defineId(AbstractMinecart.class, EntityDataSerializers.INT); - private static final EntityDataAccessor DATA_ID_DAMAGE = SynchedEntityData.defineId(AbstractMinecart.class, EntityDataSerializers.FLOAT); -@@ -84,6 +_,8 @@ +@@ -85,6 +_,8 @@ p_38135_.put(RailShape.NORTH_WEST, Pair.of(vec3i2, vec3i)); p_38135_.put(RailShape.NORTH_EAST, Pair.of(vec3i2, vec3i1)); }); @@ -18,7 +18,7 @@ protected AbstractMinecart(EntityType p_38087_, Level p_38088_) { super(p_38087_, p_38088_); -@@ -98,6 +_,14 @@ +@@ -99,6 +_,14 @@ this.zo = p_38094_; } @@ -33,7 +33,7 @@ public static AbstractMinecart createMinecart(Level p_38120_, double p_38121_, double p_38122_, double p_38123_, AbstractMinecart.Type p_38124_) { if (p_38124_ == AbstractMinecart.Type.CHEST) { return new MinecartChest(p_38120_, p_38121_, p_38122_, p_38123_); -@@ -132,7 +_,7 @@ +@@ -133,7 +_,7 @@ } public boolean isPushable() { @@ -42,7 +42,7 @@ } protected Vec3 getRelativePortalPosition(Direction.Axis p_38132_, BlockUtil.FoundRectangle p_38133_) { -@@ -295,9 +_,9 @@ +@@ -296,9 +_,9 @@ BlockPos blockpos = new BlockPos(k, i, j); BlockState blockstate = this.level().getBlockState(blockpos); this.onRails = BaseRailBlock.isRail(blockstate); @@ -54,7 +54,7 @@ this.activateMinecart(k, i, j, blockstate.getValue(PoweredRailBlock.POWERED)); } } else { -@@ -322,8 +_,11 @@ +@@ -323,8 +_,11 @@ } this.setRot(this.getYRot(), this.getXRot()); @@ -68,7 +68,7 @@ if (!list.isEmpty()) { for(Entity entity1 : list) { if (!(entity1 instanceof Player) && !(entity1 instanceof IronGolem) && !(entity1 instanceof AbstractMinecart) && !this.isVehicle() && !entity1.isPassenger()) { -@@ -334,7 +_,7 @@ +@@ -335,7 +_,7 @@ } } } else { @@ -77,7 +77,7 @@ if (!this.hasPassenger(entity) && entity.isPushable() && entity instanceof AbstractMinecart) { entity.push(this); } -@@ -359,16 +_,23 @@ +@@ -360,16 +_,23 @@ } protected void comeOffTrack() { @@ -103,7 +103,7 @@ } } -@@ -382,18 +_,19 @@ +@@ -383,18 +_,19 @@ d1 = (double)p_38156_.getY(); boolean flag = false; boolean flag1 = false; @@ -126,7 +126,7 @@ switch (railshape) { case ASCENDING_EAST: this.setDeltaMovement(vec31.add(-d3, 0.0D, 0.0D)); -@@ -439,7 +_,7 @@ +@@ -440,7 +_,7 @@ } } @@ -135,7 +135,7 @@ double d22 = this.getDeltaMovement().horizontalDistance(); if (d22 < 0.03D) { this.setDeltaMovement(Vec3.ZERO); -@@ -468,10 +_,7 @@ +@@ -469,10 +_,7 @@ d0 = d23 + d4 * d14; d2 = d10 + d5 * d14; this.setPos(d0, d1, d2); @@ -147,7 +147,7 @@ if (vec3i.getY() != 0 && Mth.floor(this.getX()) - p_38156_.getX() == vec3i.getX() && Mth.floor(this.getZ()) - p_38156_.getZ() == vec3i.getZ()) { this.setPos(this.getX(), this.getY() + (double)vec3i.getY(), this.getZ()); } else if (vec3i1.getY() != 0 && Mth.floor(this.getX()) - p_38156_.getX() == vec3i1.getX() && Mth.floor(this.getZ()) - p_38156_.getZ() == vec3i1.getZ()) { -@@ -499,7 +_,10 @@ +@@ -500,7 +_,10 @@ this.setDeltaMovement(d26 * (double)(j - p_38156_.getX()), vec35.y, d26 * (double)(i - p_38156_.getZ())); } @@ -159,7 +159,7 @@ Vec3 vec36 = this.getDeltaMovement(); double d27 = vec36.horizontalDistance(); if (d27 > 0.01D) { -@@ -563,7 +_,7 @@ +@@ -564,7 +_,7 @@ BlockState blockstate = this.level().getBlockState(new BlockPos(i, j, k)); if (BaseRailBlock.isRail(blockstate)) { @@ -168,7 +168,7 @@ p_38098_ = (double)j; if (railshape.isAscending()) { p_38098_ = (double)(j + 1); -@@ -602,7 +_,7 @@ +@@ -603,7 +_,7 @@ BlockState blockstate = this.level().getBlockState(new BlockPos(i, j, k)); if (BaseRailBlock.isRail(blockstate)) { @@ -177,7 +177,7 @@ Pair pair = exits(railshape); Vec3i vec3i = pair.getFirst(); Vec3i vec3i1 = pair.getSecond(); -@@ -664,6 +_,10 @@ +@@ -665,6 +_,10 @@ } public void push(Entity p_38165_) { @@ -188,7 +188,7 @@ if (!this.level().isClientSide) { if (!p_38165_.noPhysics && !this.noPhysics) { if (!this.hasPassenger(p_38165_)) { -@@ -697,11 +_,11 @@ +@@ -698,11 +_,11 @@ Vec3 vec32 = this.getDeltaMovement(); Vec3 vec33 = p_38165_.getDeltaMovement(); @@ -202,7 +202,7 @@ p_38165_.setDeltaMovement(vec33.multiply(0.2D, 1.0D, 0.2D)); p_38165_.push(vec32.x + d0, 0.0D, vec32.z + d1); this.setDeltaMovement(vec32.multiply(0.95D, 1.0D, 0.95D)); -@@ -818,6 +_,42 @@ +@@ -819,6 +_,42 @@ public void setCustomDisplay(boolean p_38139_) { this.getEntityData().set(DATA_ID_CUSTOM_DISPLAY, p_38139_); } diff --git a/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch index 13e9a9cfc2..508c1802dc 100644 --- a/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch @@ -1,24 +1,17 @@ --- a/net/minecraft/world/level/block/BeehiveBlock.java +++ b/net/minecraft/world/level/block/BeehiveBlock.java -@@ -70,6 +_,9 @@ - public int getAnalogOutputSignal(BlockState p_49620_, Level p_49621_, BlockPos p_49622_) { +@@ -72,6 +_,10 @@ return p_49620_.getValue(HONEY_LEVEL); } + + // Forge: Fixed MC-227255 Beehives and bee nests do not rotate/mirror correctly in structure blocks + @Override public BlockState rotate(BlockState blockState, net.minecraft.world.level.block.Rotation rotation) { return blockState.setValue(FACING, rotation.rotate(blockState.getValue(FACING))); } + @Override public BlockState mirror(BlockState blockState, net.minecraft.world.level.block.Mirror mirror) { return blockState.rotate(mirror.getRotation(blockState.getValue(FACING))); } - ++ public void playerDestroy(Level p_49584_, Player p_49585_, BlockPos p_49586_, BlockState p_49587_, @Nullable BlockEntity p_49588_, ItemStack p_49589_) { super.playerDestroy(p_49584_, p_49585_, p_49586_, p_49587_, p_49588_, p_49589_); -@@ -89,6 +_,7 @@ - List list = p_49650_.getEntitiesOfClass(Bee.class, (new AABB(p_49651_)).inflate(8.0D, 6.0D, 8.0D)); - if (!list.isEmpty()) { - List list1 = p_49650_.getEntitiesOfClass(Player.class, (new AABB(p_49651_)).inflate(8.0D, 6.0D, 8.0D)); -+ if (list1.isEmpty()) return; //Forge: Prevent Error when no players are around. - int i = list1.size(); - - for(Bee bee : list) { -@@ -110,7 +_,7 @@ + if (!p_49584_.isClientSide && p_49588_ instanceof BeehiveBlockEntity beehiveblockentity) { +@@ -115,7 +_,7 @@ boolean flag = false; if (i >= 5) { Item item = itemstack.getItem(); diff --git a/src/main/java/net/minecraftforge/client/event/RegisterColorHandlersEvent.java b/src/main/java/net/minecraftforge/client/event/RegisterColorHandlersEvent.java index 2376a39fc0..2cdf48ab26 100644 --- a/src/main/java/net/minecraftforge/client/event/RegisterColorHandlersEvent.java +++ b/src/main/java/net/minecraftforge/client/event/RegisterColorHandlersEvent.java @@ -30,12 +30,9 @@ import org.jetbrains.annotations.ApiStatus; * @see RegisterColorHandlersEvent.Block * @see RegisterColorHandlersEvent.Item */ -public abstract class RegisterColorHandlersEvent extends Event implements IModBusEvent -{ +public abstract class RegisterColorHandlersEvent extends Event implements IModBusEvent { @ApiStatus.Internal - protected RegisterColorHandlersEvent() - { - } + protected RegisterColorHandlersEvent() {} /** * Fired for registering block color handlers. @@ -45,13 +42,11 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu *

This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus}, * only on the {@linkplain LogicalSide#CLIENT logical client}.

*/ - public static class Block extends RegisterColorHandlersEvent - { + public static class Block extends RegisterColorHandlersEvent { private final BlockColors blockColors; @ApiStatus.Internal - public Block(BlockColors blockColors) - { + public Block(BlockColors blockColors) { this.blockColors = blockColors; } @@ -60,8 +55,7 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * * @see BlockColors#register(BlockColor, net.minecraft.world.level.block.Block...) */ - public BlockColors getBlockColors() - { + public BlockColors getBlockColors() { return blockColors; } @@ -71,8 +65,8 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * @param blockColor The color provider * @param blocks The blocks */ - public void register(BlockColor blockColor, net.minecraft.world.level.block.Block... blocks) - { + @SuppressWarnings("deprecation") + public void register(BlockColor blockColor, net.minecraft.world.level.block.Block... blocks) { blockColors.register(blockColor, blocks); } } @@ -88,14 +82,12 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu *

This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus}, * only on the {@linkplain LogicalSide#CLIENT logical client}.

*/ - public static class Item extends RegisterColorHandlersEvent - { + public static class Item extends RegisterColorHandlersEvent { private final ItemColors itemColors; private final BlockColors blockColors; @ApiStatus.Internal - public Item(ItemColors itemColors, BlockColors blockColors) - { + public Item(ItemColors itemColors, BlockColors blockColors) { this.itemColors = itemColors; this.blockColors = blockColors; } @@ -105,8 +97,7 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * * @see ItemColors#register(ItemColor, ItemLike...) */ - public ItemColors getItemColors() - { + public ItemColors getItemColors() { return itemColors; } @@ -114,8 +105,7 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * {@return the block colors registry} * This should only be used for referencing or delegating item colors to their respective block colors. */ - public BlockColors getBlockColors() - { + public BlockColors getBlockColors() { return blockColors; } @@ -125,8 +115,8 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * @param itemColor The color provider * @param items The items */ - public void register(ItemColor itemColor, ItemLike... items) - { + @SuppressWarnings("deprecation") + public void register(ItemColor itemColor, ItemLike... items) { itemColors.register(itemColor, items); } } @@ -135,21 +125,16 @@ public abstract class RegisterColorHandlersEvent extends Event implements IModBu * Allows registration of custom {@link ColorResolver} implementations to be used with * {@link net.minecraft.world.level.BlockAndTintGetter#getBlockTint(BlockPos, ColorResolver)}. */ - public static class ColorResolvers extends RegisterColorHandlersEvent - { + public static class ColorResolvers extends RegisterColorHandlersEvent { private final ImmutableList.Builder builder; @ApiStatus.Internal - public ColorResolvers(ImmutableList.Builder builder) - { + public ColorResolvers(ImmutableList.Builder builder) { this.builder = builder; } - public void register(ColorResolver resolver) - { + public void register(ColorResolver resolver) { this.builder.add(resolver); } - } - } diff --git a/src/main/java/net/minecraftforge/common/ForgeSpawnEggItem.java b/src/main/java/net/minecraftforge/common/ForgeSpawnEggItem.java index cb671c14fa..3e1351d3e9 100644 --- a/src/main/java/net/minecraftforge/common/ForgeSpawnEggItem.java +++ b/src/main/java/net/minecraftforge/common/ForgeSpawnEggItem.java @@ -29,36 +29,32 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; -public class ForgeSpawnEggItem extends SpawnEggItem -{ +public class ForgeSpawnEggItem extends SpawnEggItem { private static final List MOD_EGGS = new ArrayList<>(); private static final Map, ForgeSpawnEggItem> TYPE_MAP = new IdentityHashMap<>(); private final Supplier> typeSupplier; - public ForgeSpawnEggItem(Supplier> type, int backgroundColor, int highlightColor, Properties props) - { - super((EntityType) null, backgroundColor, highlightColor, props); + @SuppressWarnings("deprecation") + public ForgeSpawnEggItem(Supplier> type, int backgroundColor, int highlightColor, Properties props) { + super((EntityType)null, backgroundColor, highlightColor, props); this.typeSupplier = type; MOD_EGGS.add(this); } @Override - public EntityType getType(@Nullable CompoundTag tag) - { + public EntityType getType(@Nullable CompoundTag tag) { EntityType type = super.getType(tag); return type != null ? type : typeSupplier.get(); } @Nullable - protected DispenseItemBehavior createDispenseBehavior() - { + protected DispenseItemBehavior createDispenseBehavior() { return DEFAULT_DISPENSE_BEHAVIOR; } @Nullable - public static SpawnEggItem fromEntityType(@Nullable EntityType type) - { + public static SpawnEggItem fromEntityType(@Nullable EntityType type) { SpawnEggItem ret = TYPE_MAP.get(type); return ret != null ? ret : SpawnEggItem.byId(type); } @@ -68,39 +64,30 @@ public class ForgeSpawnEggItem extends SpawnEggItem return this.typeSupplier.get(); } - private static final DispenseItemBehavior DEFAULT_DISPENSE_BEHAVIOR = (source, stack) -> - { - Direction face = source.getBlockState().getValue(DispenserBlock.FACING); + private static final DispenseItemBehavior DEFAULT_DISPENSE_BEHAVIOR = (source, stack) -> { + Direction face = source.state().getValue(DispenserBlock.FACING); EntityType type = ((SpawnEggItem)stack.getItem()).getType(stack.getTag()); - try - { - type.spawn(source.getLevel(), stack, null, source.getPos().relative(face), MobSpawnType.DISPENSER, face != Direction.UP, false); - } - catch (Exception exception) - { - DispenseItemBehavior.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", source.getPos(), exception); + try { + type.spawn(source.level(), stack, null, source.pos().relative(face), MobSpawnType.DISPENSER, face != Direction.UP, false); + } catch (Exception exception) { + DispenseItemBehavior.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", source.pos(), exception); return ItemStack.EMPTY; } stack.shrink(1); - source.getLevel().gameEvent(GameEvent.ENTITY_PLACE, source.getPos(), GameEvent.Context.of(source.getBlockState())); + source.level().gameEvent(GameEvent.ENTITY_PLACE, source.pos(), GameEvent.Context.of(source.state())); return stack; }; @Mod.EventBusSubscriber(modid = "forge", bus = Mod.EventBusSubscriber.Bus.MOD) - private static class CommonHandler - { + private static class CommonHandler { @SubscribeEvent - public static void onCommonSetup(FMLCommonSetupEvent event) - { - MOD_EGGS.forEach(egg -> - { + public static void onCommonSetup(FMLCommonSetupEvent event) { + MOD_EGGS.forEach(egg -> { DispenseItemBehavior dispenseBehavior = egg.createDispenseBehavior(); if (dispenseBehavior != null) - { DispenserBlock.registerBehavior(egg, dispenseBehavior); - } TYPE_MAP.put(egg.typeSupplier.get(), egg); }); @@ -108,13 +95,11 @@ public class ForgeSpawnEggItem extends SpawnEggItem } @Mod.EventBusSubscriber(value = Dist.CLIENT, modid = "forge", bus = Mod.EventBusSubscriber.Bus.MOD) - private static class ColorRegisterHandler - { + private static class ColorRegisterHandler { @SubscribeEvent(priority = EventPriority.HIGHEST) - public static void registerSpawnEggColors(RegisterColorHandlersEvent.Item event) - { + public static void registerSpawnEggColors(RegisterColorHandlersEvent.Item event) { MOD_EGGS.forEach(egg -> - event.getItemColors().register((stack, layer) -> egg.getColor(layer), egg) + event.register((stack, layer) -> egg.getColor(layer), egg) ); } } diff --git a/src/main/java/net/minecraftforge/fluids/DispenseFluidContainer.java b/src/main/java/net/minecraftforge/fluids/DispenseFluidContainer.java index 477dc42f3a..7710db9490 100644 --- a/src/main/java/net/minecraftforge/fluids/DispenseFluidContainer.java +++ b/src/main/java/net/minecraftforge/fluids/DispenseFluidContainer.java @@ -6,8 +6,8 @@ package net.minecraftforge.fluids; import net.minecraft.world.level.block.DispenserBlock; +import net.minecraft.core.dispenser.BlockSource; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; -import net.minecraft.core.BlockSource; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.DispenserBlockEntity; import net.minecraft.core.Direction; @@ -21,12 +21,10 @@ import org.jetbrains.annotations.NotNull; /** * Fills or drains a fluid container item using a Dispenser. */ -public class DispenseFluidContainer extends DefaultDispenseItemBehavior -{ +public class DispenseFluidContainer extends DefaultDispenseItemBehavior { private static final DispenseFluidContainer INSTANCE = new DispenseFluidContainer(); - public static DispenseFluidContainer getInstance() - { + public static DispenseFluidContainer getInstance() { return INSTANCE; } @@ -36,44 +34,32 @@ public class DispenseFluidContainer extends DefaultDispenseItemBehavior @Override @NotNull - public ItemStack execute(@NotNull BlockSource source, @NotNull ItemStack stack) - { + public ItemStack execute(@NotNull BlockSource source, @NotNull ItemStack stack) { if (FluidUtil.getFluidContained(stack).isPresent()) - { return dumpContainer(source, stack); - } else - { return fillContainer(source, stack); - } } /** * Picks up fluid in front of a Dispenser and fills a container with it. */ @NotNull - private ItemStack fillContainer(@NotNull BlockSource source, @NotNull ItemStack stack) - { - Level level = source.getLevel(); - Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING); - BlockPos blockpos = source.getPos().relative(dispenserFacing); + private ItemStack fillContainer(@NotNull BlockSource source, @NotNull ItemStack stack) { + Level level = source.level(); + Direction dispenserFacing = source.state().getValue(DispenserBlock.FACING); + BlockPos blockpos = source.pos().relative(dispenserFacing); FluidActionResult actionResult = FluidUtil.tryPickUpFluid(stack, null, level, blockpos, dispenserFacing.getOpposite()); ItemStack resultStack = actionResult.getResult(); if (!actionResult.isSuccess() || resultStack.isEmpty()) - { return super.execute(source, stack); - } if (stack.getCount() == 1) - { return resultStack; - } - else if (((DispenserBlockEntity)source.getEntity()).addItem(resultStack) < 0) - { + else if (((DispenserBlockEntity)source.blockEntity()).addItem(resultStack) < 0) this.dispenseBehavior.dispense(source, resultStack); - } ItemStack stackCopy = stack.copy(); stackCopy.shrink(1); @@ -84,40 +70,30 @@ public class DispenseFluidContainer extends DefaultDispenseItemBehavior * Drains a filled container and places the fluid in front of the Dispenser. */ @NotNull - private ItemStack dumpContainer(BlockSource source, @NotNull ItemStack stack) - { + private ItemStack dumpContainer(BlockSource source, @NotNull ItemStack stack) { ItemStack singleStack = stack.copy(); singleStack.setCount(1); IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(singleStack).orElse(null); if (fluidHandler == null) - { return super.execute(source, stack); - } FluidStack fluidStack = fluidHandler.drain(FluidType.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE); - Direction dispenserFacing = source.getBlockState().getValue(DispenserBlock.FACING); - BlockPos blockpos = source.getPos().relative(dispenserFacing); - FluidActionResult result = FluidUtil.tryPlaceFluid(null, source.getLevel(), InteractionHand.MAIN_HAND, blockpos, stack, fluidStack); + Direction dispenserFacing = source.state().getValue(DispenserBlock.FACING); + BlockPos blockpos = source.pos().relative(dispenserFacing); + FluidActionResult result = FluidUtil.tryPlaceFluid(null, source.level(), InteractionHand.MAIN_HAND, blockpos, stack, fluidStack); - if (result.isSuccess()) - { + if (result.isSuccess()) { ItemStack drainedStack = result.getResult(); if (drainedStack.getCount() == 1) - { return drainedStack; - } - else if (!drainedStack.isEmpty() && ((DispenserBlockEntity)source.getEntity()).addItem(drainedStack) < 0) - { + else if (!drainedStack.isEmpty() && ((DispenserBlockEntity)source.blockEntity()).addItem(drainedStack) < 0) this.dispenseBehavior.dispense(source, drainedStack); - } ItemStack stackCopy = drainedStack.copy(); stackCopy.shrink(1); return stackCopy; - } - else - { + } else { return this.dispenseBehavior.dispense(source, stack); } }