- 10
- 0
Код слизал отсюда <----------
Ошибки в классе OpenInventoryMessage в методе onMessage(ошибки: playerEntity) и классе CapabilityEventHandler методе attachCapability(ошибки: Entity, getEntity, addCapability)
Ошибки в классе OpenInventoryMessage в методе onMessage(ошибки: playerEntity) и классе CapabilityEventHandler методе attachCapability(ошибки: Entity, getEntity, addCapability)
OpenInventoryMessage:
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import niclic.FigurinesMod;
import niclic.handler.GuiHandler;
public class OpenInventoryMessage implements IMessage {
public OpenInventoryMessage() { }
@Override
public void fromBytes(ByteBuf buf) {
}
@Override
public void toBytes(ByteBuf buf) {
}
@Override
public IMessage onMessage(OpenInventoryMessage message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
player.openGui(FigurinesMod.instance, GuiHandler.INVENTORY_GUI_ID, player.getEntityWorld(), (int)player.posX, (int)player.posY, (int)player.posZ);
return null;
}
}
}
CapabilityEventHandler:
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import niclic.Reference;
import niclic.capc.CAPCustomInventoryProvider;
import niclic.capc.ICAPCustomInventory;
import niclic.inventory.CustomInventory;
public class CapabilityEventHandler {
public static void register(){
MinecraftForge.EVENT_BUS.register(new CapabilityEventHandler());
}
public static final ResourceLocation INVENTORY_CAP = new ResourceLocation(Reference.MOD_ID, "inventory");
@SubscribeEvent
public void attachCapability(AttachCapabilitiesEvent.Entity event) {
if (event.getEntity() instanceof EntityPlayer){
event.addCapability(INVENTORY_CAP, new CAPCustomInventoryProvider());
}
}
@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone event) {
EntityPlayer player = event.getEntityPlayer();
ICAPCustomInventory newCap = player.getCapability(CAPCustomInventoryProvider.INVENTORY_CAP, null);
ICAPCustomInventory oldCap = event.getOriginal().getCapability(CAPCustomInventoryProvider.INVENTORY_CAP, null);
newCap.copyInventory(oldCap);
}
@SubscribeEvent
public void onPlayerDeath(LivingDeathEvent event) {
if(event.getEntity() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)event.getEntity();
ICAPCustomInventory cap = player.getCapability(CAPCustomInventoryProvider.INVENTORY_CAP, null);
CustomInventory inv = cap.getInventory();
dropAllItems(player, inv);
inv.clear();
}
}
private static void dropAllItems(EntityPlayer player, CustomInventory inventory){
NonNullList<ItemStack> aitemstack = inventory.getStacks();
for (int i = 0; i < aitemstack.size(); ++i) {
if (!aitemstack.get(i).isEmpty()) {
player.dropItem(aitemstack.get(i), true, false);
}
}
}
}
- Краш-лог
-
D:\MinecraftMod2\Mod\src\main\java\niclic\handler\CapabilityEventHandler.java:27:57
java: cannot find symbol
symbol: class Entity
location: class net.minecraftforge.event.AttachCapabilitiesEvent
Краш-лог:
D:\MinecraftMod2\Mod\src\main\java\niclic\handler\CapabilityEventHandler.java:27:57
java: cannot find symbol
symbol: class Entity
location: class net.minecraftforge.event.AttachCapabilitiesEvent