Skip to content

Commit

Permalink
Merge pull request #6 from Arbee4ever/revert-4-release
Browse files Browse the repository at this point in the history
Revert "First try to organize this repo more and implementation of #3"
  • Loading branch information
Arbee4ever authored May 8, 2022
2 parents 3877d6d + 6af94cd commit 6f6605d
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 805 deletions.
32 changes: 24 additions & 8 deletions src/main/java/net/arbee/addola/Addola.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
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.entity.vehicle.ChestBoatEntity;
import net.arbee.addola.item.ChestBoatItem;
import net.arbee.addola.registries.Commands;
import net.arbee.addola.registries.Gamerules;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

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

public static final ChestBoatItem CHESTBOAT_ITEM = new ChestBoatItem(BoatEntity.Type.OAK, new FabricItemSettings().group(ItemGroup.TRANSPORTATION));

public static final EntityType<ChestBoatEntity> CHESTBOAT = Registry.register(
Registry.ENTITY_TYPE,
new Identifier("addola", "chestboat"),
FabricEntityTypeBuilder.<ChestBoatEntity>create(SpawnGroup.MISC, ChestBoatEntity::new).dimensions(EntityDimensions.fixed(1.375f, 0.5625f)).build()
);

@Override
public void onInitialize() {
AddolaGamerules.setupGamerules();
AddolaCommands.setupCommands();
AddolaEntities.setupEntities();
AddolaItems.setupItems();
Registry.register(Registry.ITEM, new Identifier("addola", "chestboat"), CHESTBOAT_ITEM);
Gamerules.setupGamerules();
Commands.setupCommands();
}
}
72 changes: 22 additions & 50 deletions src/main/java/net/arbee/addola/AddolaClient.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
package net.arbee.addola;

import io.netty.buffer.Unpooled;
import net.arbee.addola.client.render.BoatItemRenderer;
import net.arbee.addola.client.render.ChestBoatEntityRenderer;
import net.arbee.addola.client.render.ChestBoatItemRenderer;
import net.arbee.addola.entity.renderer.ChestBoatEntityRenderer;
import net.arbee.addola.entity.vehicle.ChestBoatEntity;
import net.arbee.addola.network.SpawnChestBoatEntityPacketSender;
import net.arbee.addola.registries.AddolaEntities;
import net.arbee.addola.registries.AddolaItems;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.MinecraftVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.BoatItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;

import java.util.UUID;

Expand All @@ -36,35 +16,27 @@ public class AddolaClient implements ClientModInitializer {

@Override
public void onInitializeClient() {
AddolaItems.setupItemRenderers();

EntityRendererRegistry.INSTANCE.register(AddolaEntities.CHESTBOAT, (dispatcher, context) -> new ChestBoatEntityRenderer(dispatcher));

receiveEntityPacket();
}

public void receiveEntityPacket() {
ClientSidePacketRegistry.INSTANCE.register(SpawnChestBoatEntityPacketSender.IDENTIFIER, (ctx, byteBuf) -> {
EntityType<?> et = Registry.ENTITY_TYPE.get(byteBuf.readVarInt());
UUID uuid = byteBuf.readUuid();
int entityId = byteBuf.readVarInt();
Vec3d pos = SpawnChestBoatEntityPacketSender.PacketBufUtil.readVec3d(byteBuf);
float pitch = SpawnChestBoatEntityPacketSender.PacketBufUtil.readAngle(byteBuf);
float yaw = SpawnChestBoatEntityPacketSender.PacketBufUtil.readAngle(byteBuf);
ctx.getTaskQueue().execute(() -> {
if (MinecraftClient.getInstance().world == null)
throw new IllegalStateException("Tried to spawn entity in a null world!");
Entity e = et.create(MinecraftClient.getInstance().world);
if (e == null)
throw new IllegalStateException("Failed to create instance of entity \"" + Registry.ENTITY_TYPE.getId(et) + "\"!");
e.updateTrackedPosition(pos);
e.setPos(pos.x, pos.y, pos.z);
e.pitch = pitch;
e.yaw = yaw;
e.setEntityId(entityId);
e.setUuid(uuid);
MinecraftClient.getInstance().world.addEntity(entityId, e);
});
ClientPlayNetworking.registerGlobalReceiver(SpawnChestBoatEntityPacketSender.IDENTIFIER, (client, handler, buf, responseSender) -> {
final int entityId = buf.readInt();
final UUID uuid = buf.readUuid();
final double x = buf.readDouble();
final double y = buf.readDouble();
final double z = buf.readDouble();
final double xVelocity = buf.readDouble();
final double yVelocity = buf.readDouble();
final double zVelocity = buf.readDouble();
final float pitch = buf.readFloat();
final float yaw = buf.readFloat();
final ChestBoatEntity boat = new ChestBoatEntity(Addola.CHESTBOAT, client.world);
boat.setEntityId(entityId);
boat.setUuid(uuid);
boat.setPos(x, y, z);
boat.setVelocity(xVelocity, yVelocity, zVelocity);
boat.setYaw(yaw);
boat.pitch = pitch;
client.execute(() -> client.world.addEntity(entityId, boat));
});

EntityRendererRegistry.INSTANCE.register(Addola.CHESTBOAT, (dispatcher, context) -> new ChestBoatEntityRenderer(dispatcher));
}
}
29 changes: 0 additions & 29 deletions src/main/java/net/arbee/addola/client/render/BoatItemRenderer.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.arbee.addola.entity.ai.goal;

import net.arbee.addola.registries.AddolaGamerules;
import net.arbee.addola.registries.Gamerules;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.ai.goal.TemptGoal;
import net.minecraft.entity.mob.PathAwareEntity;
Expand All @@ -16,7 +16,7 @@ public EmeraldGoal(PathAwareEntity mob, double speed, Ingredient food, boolean c

@Override
public boolean canStart() {
if (this.mob.world.getGameRules().getBoolean(AddolaGamerules.VILLAGERS_FOLLOW)) {
if (this.mob.world.getGameRules().getBoolean(Gamerules.VILLAGERS_FOLLOW)) {
if (this.cooldown > 0) {
--this.cooldown;
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package net.arbee.addola.client.render;
package net.arbee.addola.entity.renderer;

import net.arbee.addola.entity.vehicle.ChestBoatEntity;
import net.minecraft.block.BlockState;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
Expand All @@ -12,10 +13,13 @@
import net.minecraft.client.render.entity.model.BoatEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.registry.Registry;

import java.rmi.registry.Registry;

public class ChestBoatEntityRenderer extends EntityRenderer<ChestBoatEntity> {
protected final BoatEntityModel model = new BoatEntityModel();
Expand Down Expand Up @@ -54,12 +58,10 @@ public void render(ChestBoatEntity chestBoatEntity, float f, float g, MatrixStac
VertexConsumer vertexConsumer2 = vertexConsumerProvider.getBuffer(RenderLayer.getWaterMask());
this.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);

BlockState blockEntity = Registry.BLOCK.get(new Identifier(chestBoatEntity.getBlockEntity())).getDefaultState();
matrixStack.scale(-0.9F, -0.9F, 0.9F);
matrixStack.translate(-0.1D, -0.15D, -0.5D);

MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(blockEntity, matrixStack, vertexConsumerProvider, i, OverlayTexture.DEFAULT_UV);
MinecraftClient.getInstance().getBlockRenderManager().renderBlockAsEntity(Blocks.CHEST.getDefaultState(), matrixStack, vertexConsumerProvider, i, 0);

matrixStack.pop();
super.render(chestBoatEntity, f, g, matrixStack, vertexConsumerProvider, i);
Expand All @@ -69,4 +71,13 @@ public void render(ChestBoatEntity chestBoatEntity, float f, float g, MatrixStac
public Identifier getTexture(ChestBoatEntity chestBoatEntity) {
return TEXTURES[chestBoatEntity.getBoatType().ordinal()];
}

protected Block readCustomDataFromTag(CompoundTag tag) {
if (tag.contains("Block", 8)) {
tag.getString("Block");
return Blocks.CHEST;
} else {
return Blocks.CHEST;
}
}
}
Loading

0 comments on commit 6f6605d

Please sign in to comment.