Created
February 4, 2017 07:28
-
-
Save Daomephsta/2c1ab54b4260d02b638ebf63b3c8cbbd to your computer and use it in GitHub Desktop.
Seat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package leviathan143.wildblueyonder.common.watercraft.entities; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.util.EnumHand; | |
import net.minecraft.world.World; | |
public class EntitySeat extends EntityWatercraftPart | |
{ | |
public EntitySeat(World world) | |
{ | |
super(world); | |
this.setSize(0.5F, 0.5F); | |
} | |
public EntitySeat(EntityWatercraft parent, int deckX, int deckZ) | |
{ | |
super(parent, deckX, deckZ); | |
this.setSize(0.5F, 0.5F); | |
} | |
@Override | |
public double getMountedYOffset() | |
{ | |
return super.getMountedYOffset() - 0.3F; | |
} | |
@Override | |
public boolean processInitialInteract(EntityPlayer player, EnumHand hand) | |
{ | |
if (player.isSneaking()) | |
{ | |
return false; | |
} | |
else | |
{ | |
if (!this.world.isRemote) | |
{ | |
player.startRiding(this, true); | |
} | |
return true; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package leviathan143.wildblueyonder.common.watercraft.entities; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.util.math.Vec3d; | |
import net.minecraft.world.World; | |
public class EntityWatercraftPart extends Entity | |
{ | |
private static final String DECK_X = "deck_x"; | |
private static final String DECK_Z = "deck_z"; | |
private EntityWatercraft parent; | |
private Vec3d basePosition = new Vec3d(0, 0, 0); | |
private Vec3d pos; | |
public EntityWatercraftPart(EntityWatercraft parent, int deckX, int deckZ) | |
{ | |
super(parent.world); | |
this.parent = parent; | |
basePosition = new Vec3d(deckX, 0.0D, deckZ); | |
} | |
public EntityWatercraftPart(World world) | |
{ | |
super(world); | |
} | |
@Override | |
protected void entityInit() | |
{} | |
@Override | |
public boolean canBeCollidedWith() | |
{ | |
return true; | |
} | |
public void rotateYaw(float yaw) | |
{ | |
pos = basePosition.rotateYaw((float) Math.toRadians(yaw)); | |
} | |
public Vec3d getPos() | |
{ | |
return pos; | |
} | |
@Override | |
protected void readEntityFromNBT(NBTTagCompound nbt) | |
{ | |
if(this.getRidingEntity() instanceof EntityWatercraft) | |
this.parent = (EntityWatercraft) this.getRidingEntity(); | |
this.basePosition = new Vec3d(nbt.getInteger(DECK_X), 0, nbt.getInteger(DECK_Z)); | |
} | |
@Override | |
protected void writeEntityToNBT(NBTTagCompound nbt) | |
{ | |
nbt.setInteger(DECK_X, (int) basePosition.xCoord); | |
nbt.setInteger(DECK_Z, (int) basePosition.zCoord); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package leviathan143.wildblueyonder.common.core; | |
import leviathan143.wildblueyonder.common.core.WildBlueYonder.Constants; | |
import leviathan143.wildblueyonder.common.watercraft.entities.*; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.util.ResourceLocation; | |
import net.minecraftforge.fml.common.registry.EntityRegistry; | |
public class ModEntities | |
{ | |
private static int entityID = 0; | |
public static void register() | |
{ | |
//Same as the vanilla boat | |
registerEntity(EntityWatercraft.class, "watercraft", 80, 3, true); | |
registerEntity(EntitySeat.class, "seat", 80, 3, true); | |
} | |
private static void registerEntity(Class<? extends Entity> entityClass, String entityName, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) | |
{ | |
EntityRegistry.registerModEntity(new ResourceLocation(Constants.MODID, entityName), entityClass, entityName, entityID, WildBlueYonder.instance, trackingRange, updateFrequency, sendsVelocityUpdates); | |
entityID++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment