添加集装箱获取方式

This commit is contained in:
17146 2024-11-28 21:45:02 +08:00
parent f0b1d5f2c8
commit fe130e8eec
4 changed files with 37 additions and 6 deletions

View file

@ -88,12 +88,15 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
@Override
public void load(CompoundTag compound) {
super.load(compound);
if (compound.contains("Entity")) {
entity.deserializeNBT(compound.getCompound("Entity"));
}
if (compound.contains("EntityType")) {
this.entityType = EntityType.byString(compound.getString("EntityType")).orElse(null);
}
if (compound.contains("Entity") && this.entityType != null && this.level != null) {
this.entity = this.entityType.create(this.level);
if (entity != null) {
entity.load(compound.getCompound("Entity"));
}
}
this.tick = compound.getInt("Tick");
}

View file

@ -1,8 +1,9 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -159,6 +160,11 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
if (player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) {
ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)){
player.drop(stack, false);
}
this.discard();
return InteractionResult.sidedSuccess(this.level().isClientSide());
}

View file

@ -1,9 +1,10 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig;
import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool;
@ -163,6 +164,11 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
if (player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) {
ItemStack stack = ContainerBlockItem.createInstance(this);
if (!player.addItem(stack)) {
player.drop(stack, false);
}
this.discard();
return InteractionResult.sidedSuccess(this.level().isClientSide());
}

View file

@ -6,11 +6,14 @@ import com.atsuishio.superbwarfare.init.ModBlocks;
import com.atsuishio.superbwarfare.init.ModEntities;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraftforge.client.extensions.common.IClientItemExtensions;
import software.bernie.geckolib.animatable.GeoItem;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -27,7 +30,20 @@ public class ContainerBlockItem extends BlockItem implements GeoItem {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public ContainerBlockItem() {
super(ModBlocks.CONTAINER.get(), new Item.Properties());
super(ModBlocks.CONTAINER.get(), new Item.Properties().stacksTo(1));
}
@Override
public InteractionResult place(BlockPlaceContext pContext) {
ItemStack stack = pContext.getItemInHand();
Player player = pContext.getPlayer();
if (player != null) {
var tag = BlockItem.getBlockEntityData(stack);
if (tag != null && tag.get("Entity") != null) {
player.getInventory().removeItem(stack);
}
}
return super.place(pContext);
}
private PlayState predicate(AnimationState<ContainerBlockItem> event) {