mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
1.20.2-rc1
This commit is contained in:
12 files changed
+85
-146
No files matched your search
@@ -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
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
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
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
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<ColorResolver> builder;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ColorResolvers(ImmutableList.Builder<ColorResolver> builder)
|
||||
{
|
||||
public ColorResolvers(ImmutableList.Builder<ColorResolver> builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
public void register(ColorResolver resolver)
|
||||
{
|
||||
public void register(ColorResolver resolver) {
|
||||
this.builder.add(resolver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<ForgeSpawnEggItem> MOD_EGGS = new ArrayList<>();
|
||||
private static final Map<EntityType<? extends Mob>, ForgeSpawnEggItem> TYPE_MAP = new IdentityHashMap<>();
|
||||
private final Supplier<? extends EntityType<? extends Mob>> typeSupplier;
|
||||
|
||||
public ForgeSpawnEggItem(Supplier<? extends EntityType<? extends Mob>> type, int backgroundColor, int highlightColor, Properties props)
|
||||
{
|
||||
super((EntityType<? extends Mob>) null, backgroundColor, highlightColor, props);
|
||||
@SuppressWarnings("deprecation")
|
||||
public ForgeSpawnEggItem(Supplier<? extends EntityType<? extends Mob>> type, int backgroundColor, int highlightColor, Properties props) {
|
||||
super((EntityType<? extends Mob>)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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user