Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ayamitsu.popupvillagerhead.network;
- import ayamitsu.popupvillagerhead.PopupVillagerHead;
- import cpw.mods.fml.common.network.simpleimpl.IMessage;
- import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
- import cpw.mods.fml.common.network.simpleimpl.MessageContext;
- import io.netty.buffer.ByteBuf;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.passive.EntityVillager;
- import net.minecraft.world.World;
- import java.util.List;
- /**
- * Created by ayamitsu0321 on 2014/08/12.
- */
- public class MessagePopupHead implements IMessage, IMessageHandler<MessagePopupHead, IMessage> {
- public int entityId = 0;
- public boolean data = false;
- public boolean sent = false;
- public MessagePopupHead() {}
- public MessagePopupHead(EntityVillager villager) {
- this.entityId = villager.getEntityId();
- this.data = villager.getEntityData().getBoolean("PoppedupHead");
- }
- @Override
- public void fromBytes(ByteBuf buf) {
- this.entityId = buf.readInt();
- this.data = buf.readBoolean();
- System.out.println("puts " + this.entityId + this.data);
- }
- @Override
- public void toBytes(ByteBuf buf) {
- buf.writeInt(this.entityId);
- buf.writeBoolean(this.data);
- System.out.println("puts toBytes");
- }
- @Override
- public IMessage onMessage(MessagePopupHead message, MessageContext ctx) {
- World world = PopupVillagerHead.proxy.getWorldClient();
- @SuppressWarnings("unchecked")
- List<Entity> entityList = world.getLoadedEntityList();
- for (Entity entity : entityList) {
- System.out.println("check " + entity.getEntityId());
- //引数のmessageから変数を取る。これ、クラス分けたほうが事故が少ないかも。
- if (entity.getEntityId() == message.entityId) {
- //こっちも引数のmessageから変数を取る。
- entity.getEntityData().setBoolean("PoppedupHead", message.data);
- System.out.println("puts setBoolean");
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment