EntityMinecartCommandBlock .java

net.minecraft.entity.EntityMinecartCommandBlock (class, 147 lines): members: activatorRailCooldown, getCommandBlockLogic, commandBlockLogic, interactFirst.

net.minecraft.entityclass147 linescommonextends EntityMinecart4.6 KB

API Surface (16)

void updateCommand()
int func_145751_f()
void func_145757_a(ByteBuf p_145757_1_)
BlockPos getPosition()
Vec3 getPositionVector()
World getEntityWorld()
Entity getCommandSenderEntity()
void entityInit()
void readEntityFromNBT(NBTTagCompound tagCompund)
void writeEntityToNBT(NBTTagCompound tagCompound)
EntityMinecart.EnumMinecartType getMinecartType()
IBlockState getDefaultDisplayTile()
CommandBlockLogic getCommandBlockLogic()
void onActivatorRailPass(int x, int y, int z, boolean receivingPower)
boolean interactFirst(EntityPlayer playerIn)
void onDataWatcherUpdate(int dataID)

Fields & Constants (2)

commandBlockLogic
activatorRailCooldown

Full Source

EntityMinecartCommandBlock.java147 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.entity;
2
3
import io.netty.buffer.ByteBuf;
4
import net.minecraft.block.state.IBlockState;
5
import net.minecraft.command.server.CommandBlockLogic;
6
import net.minecraft.entity.item.EntityMinecart;
7
import net.minecraft.entity.player.EntityPlayer;
8
import net.minecraft.init.Blocks;
9
import net.minecraft.nbt.NBTTagCompound;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.IChatComponent;
12
import net.minecraft.util.Vec3;
13
import net.minecraft.world.World;
14
15
public class EntityMinecartCommandBlock extends EntityMinecart
16
{
17
    private final CommandBlockLogic commandBlockLogic = new CommandBlockLogic()
18
    {
19
        public void updateCommand()
20
        {
21
            EntityMinecartCommandBlock.this.getDataWatcher().updateObject(23, this.getCommand());
22
            EntityMinecartCommandBlock.this.getDataWatcher().updateObject(24, IChatComponent.Serializer.componentToJson(this.getLastOutput()));
23
        }
24
        public int func_145751_f()
25
        {
26
            return 1;
27
        }
28
        public void func_145757_a(ByteBuf p_145757_1_)
29
        {
30
            p_145757_1_.writeInt(EntityMinecartCommandBlock.this.getEntityId());
31
        }
32
        public BlockPos getPosition()
33
        {
34
            return new BlockPos(EntityMinecartCommandBlock.this.posX, EntityMinecartCommandBlock.this.posY + 0.5D, EntityMinecartCommandBlock.this.posZ);
35
        }
36
        public Vec3 getPositionVector()
37
        {
38
            return new Vec3(EntityMinecartCommandBlock.this.posX, EntityMinecartCommandBlock.this.posY, EntityMinecartCommandBlock.this.posZ);
39
        }
40
        public World getEntityWorld()
41
        {
42
            return EntityMinecartCommandBlock.this.worldObj;
43
        }
44
        public Entity getCommandSenderEntity()
45
        {
46
            return EntityMinecartCommandBlock.this;
47
        }
48
    };
49
50
    /** Cooldown before command block logic runs again in ticks */
51
    private int activatorRailCooldown = 0;
52
53
    public EntityMinecartCommandBlock(World worldIn)
54
    {
55
        super(worldIn);
56
    }
57
58
    public EntityMinecartCommandBlock(World worldIn, double x, double y, double z)
59
    {
60
        super(worldIn, x, y, z);
61
    }
62
63
    protected void entityInit()
64
    {
65
        super.entityInit();
66
        this.getDataWatcher().addObject(23, "");
67
        this.getDataWatcher().addObject(24, "");
68
    }
69
70
    /**
71
     * (abstract) Protected helper method to read subclass entity data from NBT.
72
     */
73
    protected void readEntityFromNBT(NBTTagCompound tagCompund)
74
    {
75
        super.readEntityFromNBT(tagCompund);
76
        this.commandBlockLogic.readDataFromNBT(tagCompund);
77
        this.getDataWatcher().updateObject(23, this.getCommandBlockLogic().getCommand());
78
        this.getDataWatcher().updateObject(24, IChatComponent.Serializer.componentToJson(this.getCommandBlockLogic().getLastOutput()));
79
    }
80
81
    /**
82
     * (abstract) Protected helper method to write subclass entity data to NBT.
83
     */
84
    protected void writeEntityToNBT(NBTTagCompound tagCompound)
85
    {
86
        super.writeEntityToNBT(tagCompound);
87
        this.commandBlockLogic.writeDataToNBT(tagCompound);
88
    }
89
90
    public EntityMinecart.EnumMinecartType getMinecartType()
91
    {
92
        return EntityMinecart.EnumMinecartType.COMMAND_BLOCK;
93
    }
94
95
    public IBlockState getDefaultDisplayTile()
96
    {
97
        return Blocks.command_block.getDefaultState();
98
    }
99
100
    public CommandBlockLogic getCommandBlockLogic()
101
    {
102
        return this.commandBlockLogic;
103
    }
104
105
    /**
106
     * Called every tick the minecart is on an activator rail. Args: x, y, z, is the rail receiving power
107
     */
108
    public void onActivatorRailPass(int x, int y, int z, boolean receivingPower)
109
    {
110
        if (receivingPower && this.ticksExisted - this.activatorRailCooldown >= 4)
111
        {
112
            this.getCommandBlockLogic().trigger(this.worldObj);
113
            this.activatorRailCooldown = this.ticksExisted;
114
        }
115
    }
116
117
    /**
118
     * First layer of player interaction
119
     */
120
    public boolean interactFirst(EntityPlayer playerIn)
121
    {
122
        this.commandBlockLogic.tryOpenEditCommandBlock(playerIn);
123
        return false;
124
    }
125
126
    public void onDataWatcherUpdate(int dataID)
127
    {
128
        super.onDataWatcherUpdate(dataID);
129
130
        if (dataID == 24)
131
        {
132
            try
133
            {
134
                this.commandBlockLogic.setLastOutput(IChatComponent.Serializer.jsonToComponent(this.getDataWatcher().getWatchableObjectString(24)));
135
            }
136
            catch (Throwable var3)
137
            {
138
                ;
139
            }
140
        }
141
        else if (dataID == 23)
142
        {
143
            this.commandBlockLogic.setCommand(this.getDataWatcher().getWatchableObjectString(23));
144
        }
145
    }
146
}
147

Deobfuscated MCP 1.8.9 source of EntityMinecartCommandBlock from Marcelektro/MavenMCP-1.8.9 (net/minecraft/entity/EntityMinecartCommandBlock.java), stored verbatim.