Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9dd4861
commit 899b78c
Showing
7 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
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
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
121 changes: 121 additions & 0 deletions
121
src/main/java/net/dries007/tfc/client/render/RenderBoatTFC.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
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
99 changes: 99 additions & 0 deletions
99
src/main/java/net/dries007/tfc/objects/entity/EntityBoatTFC.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.