Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/main/java/net/arbee/addola/Addola.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package net.arbee.addola;

import net.arbee.addola.registries.AddolaCommands;
import net.arbee.addola.registries.AddolaEntities;
import net.arbee.addola.registries.AddolaGamerules;
import net.arbee.addola.registries.AddolaItems;
import net.arbee.addola.registries.*;
import net.fabricmc.api.ModInitializer;

public class Addola implements ModInitializer {
public static final String MOD_NAME = "Addola";

public static final String MOD_ID = "addola";
@Override
public void onInitialize() {
AddolaGamerules.setupGamerules();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.arbee.addola.client.render;

import net.arbee.addola.entity.vehicle.ChestBoatEntity;
import net.arbee.addola.mixins.BoatEntityRendererAccess;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.OverlayTexture;
Expand All @@ -19,11 +20,10 @@

public class ChestBoatEntityRenderer extends EntityRenderer<ChestBoatEntity> {
protected final BoatEntityModel model = new BoatEntityModel();
private static final Identifier[] TEXTURES = new Identifier[]{new Identifier("textures/entity/boat/oak.png"), new Identifier("textures/entity/boat/spruce.png"), new Identifier("textures/entity/boat/birch.png"), new Identifier("textures/entity/boat/jungle.png"), new Identifier("textures/entity/boat/acacia.png"), new Identifier("textures/entity/boat/dark_oak.png")};

public ChestBoatEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher);
this.shadowRadius = 0.8F;
shadowRadius = 0.8F;
}

public void render(ChestBoatEntity chestBoatEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) {
Expand All @@ -47,26 +47,26 @@ public void render(ChestBoatEntity chestBoatEntity, float f, float g, MatrixStac

matrixStack.scale(-1.0F, -1.0F, 1.0F);
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
this.model.setAngles(chestBoatEntity, g, 0.0F, -0.1F, 0.0F, 0.0F);
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(this.model.getLayer(this.getTexture(chestBoatEntity)));
this.model.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
model.setAngles(chestBoatEntity, g, 0.0F, -0.1F, 0.0F, 0.0F);
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(model.getLayer(getTexture(chestBoatEntity)));
model.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
if (!chestBoatEntity.isSubmergedInWater()) {
VertexConsumer vertexConsumer2 = vertexConsumerProvider.getBuffer(RenderLayer.getWaterMask());
this.model.getBottom().render(matrixStack, vertexConsumer2, i, OverlayTexture.DEFAULT_UV);
model.getBottom().render(matrixStack, vertexConsumer2, i, OverlayTexture.DEFAULT_UV);
}
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.0D, -0.05D, -0.5D);
matrixStack.translate(-0.0D, -0.225D, -0.5D);

BlockState blockEntity = Registry.BLOCK.get(new Identifier(chestBoatEntity.getBlockEntity())).getDefaultState();
BlockState container = Registry.BLOCK.get(chestBoatEntity.getContainer()).getDefaultState();

MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(blockEntity, matrixStack, vertexConsumerProvider, i, OverlayTexture.DEFAULT_UV);
MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(container, matrixStack, vertexConsumerProvider, i, OverlayTexture.DEFAULT_UV);

matrixStack.pop();
super.render(chestBoatEntity, f, g, matrixStack, vertexConsumerProvider, i);
}

@Override
public Identifier getTexture(ChestBoatEntity chestBoatEntity) {
return TEXTURES[chestBoatEntity.getBoatType().ordinal()];
return BoatEntityRendererAccess.getTEXTURES()[chestBoatEntity.getBoatType().ordinal()];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.arbee.addola.client.render;

import net.arbee.addola.Addola;
import net.arbee.addola.entity.vehicle.ChestBoatEntity;
import net.arbee.addola.item.ChestBoatItem;
import net.arbee.addola.registries.AddolaEntities;
Expand All @@ -11,6 +10,7 @@
import net.minecraft.client.render.model.json.ModelTransformation.Mode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

public class ChestBoatItemRenderer implements BuiltinItemRendererRegistry.DynamicItemRenderer {
public static ChestBoatEntity DUMMY;
Expand All @@ -21,6 +21,9 @@ public void render(ItemStack stack, Mode mode, MatrixStack matrices, VertexConsu
DUMMY = new ChestBoatEntity(AddolaEntities.CHESTBOAT, MinecraftClient.getInstance().world);
}
DUMMY.setBoatType(((ChestBoatItem)stack.getItem()).getBoatType());
if (stack.hasTag()) {
DUMMY.setContainer(new Identifier(stack.getSubTag("EntityTag").getString("Container")));
}
EntityRenderer<? super ChestBoatEntity> renderer = MinecraftClient.getInstance().getEntityRenderDispatcher().getRenderer(DUMMY);
matrices.translate(0.5, 0, 0.5);
renderer.render(DUMMY, DUMMY.getYaw(10), 0, matrices, vertexConsumers, light);
Expand Down
79 changes: 55 additions & 24 deletions src/main/java/net/arbee/addola/entity/vehicle/ChestBoatEntity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package net.arbee.addola.entity.vehicle;

import net.arbee.addola.Addola;
import net.arbee.addola.mixins.BoatEntityAccess;
import net.arbee.addola.mixins.EntityAccess;
import net.arbee.addola.network.SpawnChestBoatEntityPacketSender;
import net.arbee.addola.registries.AddolaEntities;
import net.arbee.addola.registries.AddolaItems;
import net.minecraft.block.BarrelBlock;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.ChestBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
Expand All @@ -26,20 +23,20 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Packet;
import net.minecraft.tag.FluidTags;
import net.minecraft.text.LiteralText;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;

public class ChestBoatEntity extends BoatEntity {
private static final TrackedData<String> BLOCK_ENTITY;
private static final TrackedData<String> CONTAINER;


static {
BLOCK_ENTITY = DataTracker.registerData(ChestBoatEntity.class, TrackedDataHandlerRegistry.STRING);
CONTAINER = DataTracker.registerData(ChestBoatEntity.class, TrackedDataHandlerRegistry.STRING);
}

public ChestBoatEntity(World world, double x, double y, double z) {
Expand All @@ -59,17 +56,19 @@ public ChestBoatEntity(EntityType<? extends ChestBoatEntity> entityType, World w
public ActionResult interact(PlayerEntity player, Hand hand) {
if (((BoatEntityAccess)this).getTicksUnderwater() < 60.0F) {
if (!this.world.isClient) {
Block block = Registry.BLOCK.get(Registry.ITEM.getId(player.getMainHandStack().getItem()));
Identifier item = Registry.ITEM.getId(player.getMainHandStack().getItem());
if (player.isSneaking()) {
if (block.equals(Blocks.AIR)) {
world.spawnEntity(new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(Registry.ITEM.get(new Identifier(getBlockEntity())))));
if (item.equals(Registry.ITEM.getId(Items.AIR))) {
world.spawnEntity(new ItemEntity(world, getX(), getY() + 0.6D, getZ(), new ItemStack(Registry.ITEM.get(getContainer()))));
BoatEntity boat = new BoatEntity(world, getX(), getY(), getZ());
boat.setBoatType(getBoatType());
world.spawnEntity(boat);
boat.copyPositionAndRotation(this);
boat.pitch = 60.0F;
remove();
} else if (block.hasBlockEntity()) {
world.spawnEntity(new ItemEntity(world, getX(), getY(), getZ(), new ItemStack(Registry.ITEM.get(new Identifier(getBlockEntity())))));
setBlockEntity(Registry.ITEM.getId(player.getMainHandStack().getItem()).toString());
} else if (Registry.BLOCK.get(Registry.ITEM.getId(player.getMainHandStack().getItem())).getDefaultState() instanceof Inventory) {
world.spawnEntity(new ItemEntity(world, getX(), getY() + 0.6D, getZ(), new ItemStack(Registry.ITEM.get(getContainer()))));
setContainer(Registry.ITEM.getId(player.getMainHandStack().getItem()));
player.getMainHandStack().decrement(1);
return ActionResult.SUCCESS;
}
Expand All @@ -83,30 +82,62 @@ public ActionResult interact(PlayerEntity player, Hand hand) {
}
}

@Override
public boolean damage(DamageSource source, float amount) {
if (this.isInvulnerableTo(source)) {
return false;
} else if (!this.world.isClient && !this.removed) {
this.setDamageWobbleSide(-this.getDamageWobbleSide());
this.setDamageWobbleTicks(10);
this.setDamageWobbleStrength(this.getDamageWobbleStrength() + amount * 10.0F);
this.scheduleVelocityUpdate();
boolean bl = source.getAttacker() instanceof PlayerEntity && ((PlayerEntity)source.getAttacker()).abilities.creativeMode;
if (bl || this.getDamageWobbleStrength() > 40.0F) {
if (!bl && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
ItemStack itemStack = new ItemStack(this.asItem());
CompoundTag compoundTag = new CompoundTag();
compoundTag.putString("Container", this.getContainer().toString());
if (!compoundTag.isEmpty()) {
itemStack.putSubTag("EntityTag", compoundTag);
}
ItemEntity itemEntity = new ItemEntity(world, ((EntityAccess)this).getPos().getX() + 0.5D, ((EntityAccess)this).getPos().getY() + 0.5D, ((EntityAccess)this).getPos().getZ() + 0.5D, itemStack);
itemEntity.setToDefaultPickupDelay();
world.spawnEntity(itemEntity);
}

this.remove();
}

return true;
} else {
return true;
}
}

@Override
protected void initDataTracker() {
super.initDataTracker();
this.dataTracker.startTracking(BLOCK_ENTITY, Registry.BLOCK.getId(Blocks.CHEST).toString());
this.dataTracker.startTracking(CONTAINER, Registry.BLOCK.getId(Blocks.CHEST).toString());
}

protected void writeCustomDataToTag(CompoundTag tag) {
super.writeCustomDataToTag(tag);
tag.putString("BlockEntity", getBlockEntity());
tag.putString("Container", getContainer().toString());
}

protected void readCustomDataFromTag(CompoundTag tag) {
super.readCustomDataFromTag(tag);
if (tag.contains("BlockEntity", 8)) {
this.setBlockEntity(tag.getString("BlockEntity"));
if (tag.contains("Container", 8)) {
this.setContainer(new Identifier(tag.getString("Container")));
}
}

public void setBlockEntity(String blockEntity) {
this.dataTracker.set(BLOCK_ENTITY, blockEntity);
public void setContainer(Identifier container) {
this.dataTracker.set(CONTAINER, container.toString());
}

public String getBlockEntity() {
return this.dataTracker.get(BLOCK_ENTITY);
public Identifier getContainer() {
return new Identifier(this.dataTracker.get(CONTAINER));
}

@Override
Expand All @@ -119,7 +150,7 @@ public void updatePassengerPosition(Entity passenger) {
f = (float)((double)f + 0.2D);
}

Vec3d vec3d = (new Vec3d((double)f, 0.0D, 0.0D)).rotateY(-this.yaw * 0.017453292F - 1.5707964F);
Vec3d vec3d = (new Vec3d(f, 0.0D, 0.0D)).rotateY(-this.yaw * 0.017453292F - 1.5707964F);
passenger.updatePosition(this.getX() + vec3d.x, this.getY() + (double)g, this.getZ() + vec3d.z);
passenger.yaw += ((BoatEntityAccess)this).getYawVelocity();
passenger.setHeadYaw(passenger.getHeadYaw() + ((BoatEntityAccess)this).getYawVelocity());
Expand Down Expand Up @@ -158,6 +189,6 @@ protected boolean canAddPassenger(Entity passenger) {

@Override
public Packet<?> createSpawnPacket() {
return SpawnChestBoatEntityPacketSender.createSpawnPacket(this);
return SpawnChestBoatEntityPacketSender.create(this);
}
}
25 changes: 20 additions & 5 deletions src/main/java/net/arbee/addola/item/ChestBoatItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.arbee.addola.entity.vehicle.ChestBoatEntity;
import net.arbee.addola.mixins.BoatItemAccess;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity;
Expand All @@ -10,21 +11,24 @@
import net.minecraft.item.ItemStack;
import net.minecraft.stat.Stats;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.RaycastContext;
import net.minecraft.world.World;

import java.util.Iterator;
import java.util.List;

public class ChestBoatItem extends BoatItem {
ChestBoatItem instance = this;
private Identifier container;

public ChestBoatItem(ChestBoatEntity.Type type, Item.Settings settings) {
super(type, settings);
setContainer(Registry.BLOCK.getId(Blocks.CHEST));
settings.maxCount(1);
}

Expand All @@ -37,14 +41,14 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
} else {
Vec3d vec3d = user.getRotationVec(1.0F);
double d = 5.0D;
List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), ((BoatItemAccess)instance).getRIDERS());
List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), ((BoatItemAccess)this).getRIDERS());
if (!list.isEmpty()) {
Vec3d vec3d2 = user.getCameraPosVec(1.0F);
Iterator var11 = list.iterator();

while(var11.hasNext()) {
Entity entity = (Entity)var11.next();
Box box = entity.getBoundingBox().expand((double)entity.getTargetingMargin());
Box box = entity.getBoundingBox().expand(entity.getTargetingMargin());
if (box.contains(vec3d2)) {
return TypedActionResult.pass(itemStack);
}
Expand All @@ -53,7 +57,10 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han

if (hitResult.getType() == HitResult.Type.BLOCK) {
ChestBoatEntity chestBoatEntity = new ChestBoatEntity(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z);
chestBoatEntity.setBoatType(((BoatItemAccess)instance).getType());
chestBoatEntity.setBoatType(((BoatItemAccess)this).getType());
if (itemStack.hasTag()) {
chestBoatEntity.setContainer(new Identifier(itemStack.getSubTag("EntityTag").getString("Container")));
}
chestBoatEntity.yaw = user.yaw;
if (!world.isSpaceEmpty(chestBoatEntity, chestBoatEntity.getBoundingBox().expand(-0.1D))) {
return TypedActionResult.fail(itemStack);
Expand All @@ -75,6 +82,14 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
}

public BoatEntity.Type getBoatType() {
return ((BoatItemAccess)instance).getType();
return ((BoatItemAccess)this).getType();
}

public void setContainer(Identifier container) {
this.container = container;
}

public Identifier getContainer() {
return container;
}
}
3 changes: 2 additions & 1 deletion src/main/java/net/arbee/addola/mixins/BoatEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable<Act
ChestBoatEntity chestBoat = new ChestBoatEntity(world, instance.getX(), instance.getY(), instance.getZ());
world.spawnEntity(chestBoat);
chestBoat.copyPositionAndRotation(instance);
chestBoat.setBlockEntity(Registry.ITEM.getId(player.getMainHandStack().getItem()).toString());
chestBoat.setContainer(Registry.ITEM.getId(player.getMainHandStack().getItem()));
chestBoat.setBoatType(instance.getBoatType());
player.getMainHandStack().decrement(1);
instance.remove();
cir.setReturnValue(ActionResult.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.arbee.addola.mixins;

import net.minecraft.client.render.entity.BoatEntityRenderer;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(BoatEntityRenderer.class)
public interface BoatEntityRendererAccess {
@Accessor
static Identifier[] getTEXTURES() {
throw new AssertionError();
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/arbee/addola/mixins/EntityAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.arbee.addola.mixins;

import net.minecraft.entity.Entity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.item.BoatItem;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.function.Predicate;

@Mixin(Entity.class)
public interface EntityAccess {
@Accessor Vec3d getPos();
}
Loading