-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14e321a
commit 95ca694
Showing
27 changed files
with
692 additions
and
25 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
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/gtceu/models/item/rubber_boat.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/rubber_boat" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/gtceu/models/item/rubber_chest_boat.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/rubber_chest_boat" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/gtceu/models/item/treated_wood_boat.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/treated_wood_boat" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/assets/gtceu/models/item/treated_wood_chest_boat.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "gtceu:item/treated_wood_chest_boat" | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/main/java/com/gregtechceu/gtceu/client/renderer/entity/GTBoatRenderer.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,60 @@ | ||
package com.gregtechceu.gtceu.client.renderer.entity; | ||
|
||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.common.entity.GTBoat; | ||
import com.gregtechceu.gtceu.common.entity.GTChestBoat; | ||
|
||
import net.minecraft.client.model.BoatModel; | ||
import net.minecraft.client.model.ChestBoatModel; | ||
import net.minecraft.client.model.ListModel; | ||
import net.minecraft.client.model.geom.ModelLayerLocation; | ||
import net.minecraft.client.model.geom.ModelPart; | ||
import net.minecraft.client.renderer.entity.BoatRenderer; | ||
import net.minecraft.client.renderer.entity.EntityRendererProvider; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.vehicle.Boat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.mojang.datafixers.util.Pair; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class GTBoatRenderer extends BoatRenderer { | ||
|
||
private final Map<GTBoat.BoatType, Pair<ResourceLocation, ListModel<Boat>>> boats; | ||
|
||
public GTBoatRenderer(EntityRendererProvider.Context context, boolean chestBoat) { | ||
super(context, chestBoat); | ||
boats = Stream.of(GTBoat.BoatType.values()).collect(ImmutableMap.toImmutableMap(k -> k, | ||
(m) -> Pair.of(new ResourceLocation(GTCEu.MOD_ID, | ||
getTextureLocation(m, chestBoat)), createBoatModel(context, m, chestBoat)))); | ||
} | ||
|
||
@Override | ||
public Pair<ResourceLocation, ListModel<Boat>> getModelWithLocation(Boat boat) { | ||
if (boat instanceof GTChestBoat gtcb) { | ||
return this.boats.get(gtcb.getBoatType()); | ||
} else | ||
return this.boats.get(((GTBoat) boat).getBoatType()); | ||
} | ||
|
||
private static String getTextureLocation(GTBoat.BoatType type, boolean chest) { | ||
return chest ? "textures/entity/boat/" + type.getName() + "_chest_boat.png" : | ||
"textures/entity/boat/" + type.getName() + "_boat.png"; | ||
} | ||
|
||
private BoatModel createBoatModel(EntityRendererProvider.Context context, GTBoat.BoatType type, boolean chest) { | ||
ModelLayerLocation modelLoc = chest ? getChestBoatModelName(type) : getBoatModelName(type); | ||
ModelPart part = context.bakeLayer(modelLoc); | ||
return chest ? new ChestBoatModel(part) : new BoatModel(part); | ||
} | ||
|
||
public static ModelLayerLocation getChestBoatModelName(GTBoat.BoatType type) { | ||
return new ModelLayerLocation(new ResourceLocation(GTCEu.MOD_ID, "chest_boat/" + type.getName()), "main"); | ||
} | ||
|
||
public static ModelLayerLocation getBoatModelName(GTBoat.BoatType type) { | ||
return new ModelLayerLocation(new ResourceLocation(GTCEu.MOD_ID, "boat/" + type.getName()), "main"); | ||
} | ||
} |
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
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
123 changes: 123 additions & 0 deletions
123
src/main/java/com/gregtechceu/gtceu/common/entity/GTBoat.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,123 @@ | ||
package com.gregtechceu.gtceu.common.entity; | ||
|
||
import com.gregtechceu.gtceu.common.data.GTBlocks; | ||
import com.gregtechceu.gtceu.common.data.GTEntityTypes; | ||
import com.gregtechceu.gtceu.common.data.GTItems; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ClientGamePacketListener; | ||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.vehicle.Boat; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.Block; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
|
||
public class GTBoat extends Boat { | ||
|
||
public GTBoat(EntityType<? extends Boat> entityType, Level level) { | ||
super(entityType, level); | ||
this.blocksBuilding = true; | ||
} | ||
|
||
public GTBoat(Level level, double x, double y, double z) { | ||
super(GTEntityTypes.BOAT.get(), level); | ||
this.setPos(x, y, z); | ||
this.xo = x; | ||
this.yo = y; | ||
this.zo = z; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Component getCustomName() { | ||
return super.getCustomName(); | ||
} | ||
|
||
@Override | ||
public Packet<ClientGamePacketListener> getAddEntityPacket() { | ||
return new ClientboundAddEntityPacket(this); | ||
} | ||
|
||
@Override | ||
protected void addAdditionalSaveData(CompoundTag compound) { | ||
compound.putString("Type", getBoatType().getName()); | ||
} | ||
|
||
@Override | ||
protected void readAdditionalSaveData(CompoundTag compound) { | ||
if (compound.contains("Type")) { | ||
entityData.set(DATA_ID_TYPE, BoatType.byName(compound.getString("Type")).ordinal()); | ||
} | ||
} | ||
|
||
@Override | ||
public Item getDropItem() { | ||
return switch (BoatType.byId(this.entityData.get(DATA_ID_TYPE))) { | ||
case RUBBER -> GTItems.RUBBER_BOAT.get(); | ||
case TREATED_WOOD -> GTItems.TREATED_WOOD_BOAT.get(); | ||
}; | ||
} | ||
|
||
public void setBoatType(BoatType type) { | ||
this.entityData.set(DATA_ID_TYPE, type.ordinal()); | ||
} | ||
|
||
public BoatType getBoatType() { | ||
return BoatType.byId(entityData.get(DATA_ID_TYPE)); | ||
} | ||
|
||
@Override | ||
public void setVariant(Type variant) {} | ||
|
||
@Override | ||
public Type getVariant() { | ||
return Type.OAK; | ||
} | ||
|
||
public enum BoatType { | ||
|
||
RUBBER("rubber", GTBlocks.RUBBER_PLANK.get()), | ||
TREATED_WOOD("treated", GTBlocks.TREATED_WOOD_PLANK.get()); | ||
|
||
private final String name; | ||
private final Block planks; | ||
|
||
private static final BoatType[] VALUES = values(); | ||
|
||
private BoatType(String name, Block planks) { | ||
this.name = name; | ||
this.planks = planks; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public Block getPlanks() { | ||
return this.planks; | ||
} | ||
|
||
public String toString() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* Get a boat type by its enum ordinal | ||
*/ | ||
public static BoatType byId(int id) { | ||
if (id < 0 || id >= VALUES.length) id = 0; | ||
return VALUES[id]; | ||
} | ||
|
||
public static BoatType byName(String name) { | ||
return Arrays.stream(VALUES).filter(type -> type.getName().equals(name)).findFirst().orElse(VALUES[0]); | ||
} | ||
} | ||
} |
Oops, something went wrong.