Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added TFC boat for each wood variant (Closes #376). Closes #462.
  • Loading branch information
DisasterMoo authored and alcatrazEscapee committed Oct 11, 2019
1 parent 9dd4861 commit 899b78c
Show file tree
Hide file tree
Showing 7 changed files with 396 additions and 0 deletions.
1 change: 1 addition & 0 deletions generateResources.py
Expand Up @@ -1037,6 +1037,7 @@ def item(filename_parts, *layers, parent='item/generated'):
# WOOD STUFF
for wood_type in WOOD_TYPES:
item(('wood', 'lumber', wood_type), 'tfc:items/wood/lumber/%s' % wood_type)
item(('wood', 'boat', wood_type), 'tfc:items/wood/boat/%s' % wood_type)

# ROCK TOOLS
for rock_cat in ROCK_CATEGORIES:
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/net/dries007/tfc/client/ClientEvents.java
Expand Up @@ -45,10 +45,12 @@
import net.dries007.tfc.api.capability.size.IItemSize;
import net.dries007.tfc.api.util.IRockObject;
import net.dries007.tfc.client.button.GuiButtonPlayerInventoryTab;
import net.dries007.tfc.client.render.RenderBoatTFC;
import net.dries007.tfc.client.render.RenderFallingBlockTFC;
import net.dries007.tfc.client.render.animal.*;
import net.dries007.tfc.client.render.projectile.RenderThrownJavelin;
import net.dries007.tfc.network.PacketSwitchPlayerInventoryTab;
import net.dries007.tfc.objects.entity.EntityBoatTFC;
import net.dries007.tfc.objects.entity.EntityFallingBlockTFC;
import net.dries007.tfc.objects.entity.animal.*;
import net.dries007.tfc.objects.entity.projectile.EntityThrownJavelin;
Expand Down Expand Up @@ -82,6 +84,7 @@ public static void preInit()
RenderingRegistry.registerEntityRenderingHandler(EntityHorseTFC.class, RenderHorseTFC::new);
RenderingRegistry.registerEntityRenderingHandler(EntityDonkeyTFC.class, RenderAbstractHorseTFC::new);
RenderingRegistry.registerEntityRenderingHandler(EntityMuleTFC.class, RenderAbstractHorseTFC::new);
RenderingRegistry.registerEntityRenderingHandler(EntityBoatTFC.class, RenderBoatTFC::new);
}

@SideOnly(Side.CLIENT)
Expand Down
121 changes: 121 additions & 0 deletions src/main/java/net/dries007/tfc/client/render/RenderBoatTFC.java
@@ -0,0 +1,121 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.client.render;

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.client.model.IMultipassModel;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBoat;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import net.dries007.tfc.api.types.Tree;
import net.dries007.tfc.objects.entity.EntityBoatTFC;

import static net.dries007.tfc.api.util.TFCConstants.MOD_ID;

@SideOnly(Side.CLIENT)
@ParametersAreNonnullByDefault
public class RenderBoatTFC extends Render<EntityBoatTFC>
{
private ModelBase modelBoat = new ModelBoat();

public RenderBoatTFC(RenderManager renderManagerIn)
{
super(renderManagerIn);
this.shadowSize = 0.5F;
}

@Override
public void doRender(EntityBoatTFC entity, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
this.setupTranslation(x, y, z);
this.setupRotation(entity, entityYaw, partialTicks);
this.bindEntityTexture(entity);

if (this.renderOutlines)
{
GlStateManager.enableColorMaterial();
GlStateManager.enableOutlineMode(this.getTeamColor(entity));
}

this.modelBoat.render(entity, partialTicks, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

if (this.renderOutlines)
{
GlStateManager.disableOutlineMode();
GlStateManager.disableColorMaterial();
}

GlStateManager.popMatrix();
super.doRender(entity, x, y, z, entityYaw, partialTicks);
}

/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
@Override
protected ResourceLocation getEntityTexture(EntityBoatTFC entity)
{
final Tree wood = entity.getWood();
if (wood != null)
{
//noinspection ConstantConditions
return new ResourceLocation(MOD_ID, "textures/entity/boat/" + wood.getRegistryName().getPath().toLowerCase() + ".png");
}
// Fallback
return new ResourceLocation(MOD_ID, "textures/entity/boat/oak.png");
}

@Override
public boolean isMultipass()
{
return true;
}

@Override
public void renderMultipass(EntityBoatTFC entityIn, double x, double y, double z, float entityYaw, float partialTicks)
{
GlStateManager.pushMatrix();
this.setupTranslation(x, y, z);
this.setupRotation(entityIn, entityYaw, partialTicks);
this.bindEntityTexture(entityIn);
((IMultipassModel) this.modelBoat).renderMultipass(entityIn, partialTicks, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
GlStateManager.popMatrix();
}

private void setupRotation(EntityBoat entityIn, float entityYaw, float partialTicks)
{
GlStateManager.rotate(180.0F - entityYaw, 0.0F, 1.0F, 0.0F);
float f = (float) entityIn.getTimeSinceHit() - partialTicks;
float f1 = entityIn.getDamageTaken() - partialTicks;

if (f1 < 0.0F)
{
f1 = 0.0F;
}

if (f > 0.0F)
{
GlStateManager.rotate(MathHelper.sin(f) * f * f1 / 10.0F * (float) entityIn.getForwardDirection(), 1.0F, 0.0F, 0.0F);
}

GlStateManager.scale(-1.0F, -1.0F, 1.0F);
}

private void setupTranslation(double x, double y, double z)
{
GlStateManager.translate((float) x, (float) y + 0.375F, (float) z);
}
}
Expand Up @@ -24,6 +24,7 @@ public static void preInit()
register("sitblock", EntitySeatOn.class);
register("falling_block", EntityFallingBlockTFC.class);
register("thrown_javelin", EntityThrownJavelin.class);
register("boat", EntityBoatTFC.class);
registerLiving("sheeptfc", EntitySheepTFC.class, 0xFFFFFF, 0xFF6347);
registerLiving("cowtfc", EntityCowTFC.class, 0xA52A2A, 0xFFFFFF);
registerLiving("beartfc", EntityBearTFC.class, 0x557755, 0xF1FFF1);
Expand Down
99 changes: 99 additions & 0 deletions src/main/java/net/dries007/tfc/objects/entity/EntityBoatTFC.java
@@ -0,0 +1,99 @@
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/

package net.dries007.tfc.objects.entity;

import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.entity.item.EntityBoat;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.world.World;

import mcp.MethodsReturnNonnullByDefault;
import net.dries007.tfc.api.registries.TFCRegistries;
import net.dries007.tfc.api.types.Tree;
import net.dries007.tfc.objects.items.wood.ItemBoatTFC;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class EntityBoatTFC extends EntityBoat
{
private static final DataParameter<String> WOOD_NAME = EntityDataManager.createKey(EntityBoatTFC.class, DataSerializers.STRING);

public EntityBoatTFC(World worldIn)
{
super(worldIn);
}

public EntityBoatTFC(World worldIn, double x, double y, double z)
{
super(worldIn, x, y, z);
}

@Nullable
public Tree getWood()
{
//noinspection ConstantConditions
return TFCRegistries.TREES.getValuesCollection().stream()
.filter(x -> x.getRegistryName().getPath().equalsIgnoreCase(this.dataManager.get(WOOD_NAME)))
.findFirst().orElse(null);
}

public void setWood(@Nullable Tree wood)
{
String woodName = "";
if (wood != null)
{
//noinspection ConstantConditions
woodName = wood.getRegistryName().getPath().toLowerCase();
}
this.dataManager.set(WOOD_NAME, woodName);
}

@Override
protected void entityInit()
{
super.entityInit();
this.dataManager.register(WOOD_NAME, "");
}

@Override
public Item getItemBoat()
{
Tree wood = getWood();
if (wood != null)
{
return ItemBoatTFC.get(wood);
}
return super.getItemBoat();
}

@Override
protected void writeEntityToNBT(NBTTagCompound compound)
{
super.writeEntityToNBT(compound);
Tree wood = getWood();
if (wood != null)
{
//noinspection ConstantConditions
compound.setString("Wood", this.getWood().getRegistryName().getPath().toLowerCase());
}
}

@Override
protected void readEntityFromNBT(NBTTagCompound compound)
{
super.readEntityFromNBT(compound);
if (compound.hasKey("Wood"))
{
this.dataManager.set(WOOD_NAME, compound.getString("Wood"));
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/net/dries007/tfc/objects/items/ItemsTFC.java
Expand Up @@ -41,6 +41,7 @@
import net.dries007.tfc.objects.items.rock.ItemBrickTFC;
import net.dries007.tfc.objects.items.rock.ItemRock;
import net.dries007.tfc.objects.items.rock.ItemRockToolHead;
import net.dries007.tfc.objects.items.wood.ItemBoatTFC;
import net.dries007.tfc.objects.items.wood.ItemDoorTFC;
import net.dries007.tfc.objects.items.wood.ItemLumberTFC;
import net.dries007.tfc.objects.items.wood.ItemWoodenBucket;
Expand Down Expand Up @@ -210,7 +211,10 @@ public static void registerItems(RegistryEvent.Register<Item> event)
simpleItems.add(register(r, slab.getRegistryName().getPath(), new ItemSlabTFC(slab, slab, slab.doubleSlab), CT_DECORATIONS));

for (Tree wood : TFCRegistries.TREES.getValuesCollection())
{
simpleItems.add(register(r, "wood/lumber/" + wood.getRegistryName().getPath(), new ItemLumberTFC(wood), CT_WOOD));
simpleItems.add(register(r, "wood/boat/" + wood.getRegistryName().getPath(), new ItemBoatTFC(wood), CT_WOOD));
}

for (RockCategory cat : TFCRegistries.ROCK_CATEGORIES.getValuesCollection())
{
Expand Down

0 comments on commit 899b78c

Please sign in to comment.