所有集装箱都能放在水面上了
This commit is contained in:
parent
666da39453
commit
62bd1d5f08
2 changed files with 19 additions and 55 deletions
|
@ -20,26 +20,14 @@ public class RegisterContainersEvent extends Event implements IModBusEvent {
|
||||||
public static final List<ItemStack> containers = new ArrayList<>();
|
public static final List<ItemStack> containers = new ArrayList<>();
|
||||||
|
|
||||||
public <T extends Entity> void add(DeferredHolder<EntityType<?>, EntityType<T>> type) {
|
public <T extends Entity> void add(DeferredHolder<EntityType<?>, EntityType<T>> type) {
|
||||||
add(type.get(), false);
|
add(type.get());
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends Entity> void add(DeferredHolder<EntityType<?>, EntityType<T>> type, boolean canBePlacedAboveWater) {
|
|
||||||
add(type.get(), canBePlacedAboveWater);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Entity> void add(EntityType<T> type) {
|
public <T extends Entity> void add(EntityType<T> type) {
|
||||||
add(type, false);
|
containers.add(ContainerBlockItem.createInstance(type));
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends Entity> void add(EntityType<T> type, boolean canBePlacedAboveWater) {
|
|
||||||
containers.add(ContainerBlockItem.createInstance(type, canBePlacedAboveWater));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Entity entity) {
|
public void add(Entity entity) {
|
||||||
add(entity, false);
|
containers.add(ContainerBlockItem.createInstance(entity));
|
||||||
}
|
|
||||||
|
|
||||||
public void add(Entity entity, boolean canBePlacedAboveWater) {
|
|
||||||
containers.add(ContainerBlockItem.createInstance(entity, canBePlacedAboveWater));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.item.component.CustomData;
|
|
||||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.ClipContext;
|
import net.minecraft.world.level.ClipContext;
|
||||||
|
@ -39,6 +38,8 @@ import software.bernie.geckolib.animation.AnimationState;
|
||||||
import software.bernie.geckolib.animation.PlayState;
|
import software.bernie.geckolib.animation.PlayState;
|
||||||
import software.bernie.geckolib.util.GeckoLibUtil;
|
import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
|
|
||||||
|
import javax.annotation.ParametersAreNonnullByDefault;
|
||||||
|
|
||||||
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
|
||||||
public class ContainerBlockItem extends BlockItem implements GeoItem {
|
public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
|
|
||||||
|
@ -49,10 +50,10 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
event.add(ModEntities.HPJ_11);
|
event.add(ModEntities.HPJ_11);
|
||||||
event.add(ModEntities.ANNIHILATOR);
|
event.add(ModEntities.ANNIHILATOR);
|
||||||
event.add(ModEntities.LASER_TOWER);
|
event.add(ModEntities.LASER_TOWER);
|
||||||
event.add(ModEntities.SPEEDBOAT, true);
|
event.add(ModEntities.SPEEDBOAT);
|
||||||
event.add(ModEntities.AH_6);
|
event.add(ModEntities.AH_6);
|
||||||
event.add(ModEntities.LAV_150, true);
|
event.add(ModEntities.LAV_150);
|
||||||
event.add(ModEntities.BMP_2, true);
|
event.add(ModEntities.BMP_2);
|
||||||
event.add(ModEntities.PRISM_TANK);
|
event.add(ModEntities.PRISM_TANK);
|
||||||
event.add(ModEntities.YX_100);
|
event.add(ModEntities.YX_100);
|
||||||
event.add(ModEntities.WHEEL_CHAIR);
|
event.add(ModEntities.WHEEL_CHAIR);
|
||||||
|
@ -67,22 +68,13 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResult useOn(UseOnContext context) {
|
public @NotNull InteractionResult useOn(@NotNull UseOnContext context) {
|
||||||
ItemStack stack = context.getItemInHand();
|
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
|
||||||
|
|
||||||
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
|
||||||
return InteractionResult.PASS;
|
return InteractionResult.PASS;
|
||||||
}
|
}
|
||||||
return super.useOn(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level level, Player player, @NotNull InteractionHand hand) {
|
@ParametersAreNonnullByDefault
|
||||||
ItemStack stack = player.getItemInHand(hand);
|
public @NotNull InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
|
||||||
|
|
||||||
if (data != null && data.copyTag().getBoolean("CanPlacedAboveWater")) {
|
|
||||||
BlockHitResult playerPOVHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.WATER);
|
BlockHitResult playerPOVHitResult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.WATER);
|
||||||
if (playerPOVHitResult.getType() == HitResult.Type.MISS) {
|
if (playerPOVHitResult.getType() == HitResult.Type.MISS) {
|
||||||
return super.use(level, player, hand);
|
return super.use(level, player, hand);
|
||||||
|
@ -91,8 +83,6 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
InteractionResult interactionresult = super.useOn(new UseOnContext(player, hand, blockHitResult));
|
InteractionResult interactionresult = super.useOn(new UseOnContext(player, hand, blockHitResult));
|
||||||
return new InteractionResultHolder<>(interactionresult, player.getItemInHand(hand));
|
return new InteractionResultHolder<>(interactionresult, player.getItemInHand(hand));
|
||||||
}
|
}
|
||||||
return super.use(level, player, hand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull InteractionResult place(BlockPlaceContext pContext) {
|
public @NotNull InteractionResult place(BlockPlaceContext pContext) {
|
||||||
|
@ -144,14 +134,6 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createInstance(Entity entity) {
|
public static ItemStack createInstance(Entity entity) {
|
||||||
return createInstance(entity, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack createInstance(EntityType<?> entityType) {
|
|
||||||
return createInstance(entityType, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack createInstance(Entity entity, boolean canPlacedAboveWater) {
|
|
||||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||||
|
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||||
|
@ -167,22 +149,16 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
|
||||||
|
|
||||||
tag.putString("EntityType", EntityType.getKey(entity.getType()).toString());
|
tag.putString("EntityType", EntityType.getKey(entity.getType()).toString());
|
||||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
|
||||||
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createInstance(EntityType<?> entityType, boolean canPlacedAboveWater) {
|
public static ItemStack createInstance(EntityType<?> entityType) {
|
||||||
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
ItemStack stack = new ItemStack(ModBlocks.CONTAINER.get());
|
||||||
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
var data = stack.get(DataComponents.BLOCK_ENTITY_DATA);
|
||||||
var tag = data != null ? data.copyTag() : new CompoundTag();
|
var tag = data != null ? data.copyTag() : new CompoundTag();
|
||||||
|
|
||||||
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
tag.putString("EntityType", EntityType.getKey(entityType).toString());
|
||||||
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
BlockItem.setBlockEntityData(stack, ModBlockEntities.CONTAINER.get(), tag);
|
||||||
tag.putBoolean("CanPlacedAboveWater", canPlacedAboveWater);
|
|
||||||
stack.set(DataComponents.BLOCK_ENTITY_DATA, CustomData.of(tag));
|
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue