Skip to content

Commit

Permalink
argh! part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Aug 10, 2024
1 parent 11aeb70 commit 2cb5058
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 375 deletions.
4 changes: 3 additions & 1 deletion src/main/java/net/id/paradiselost/api/BlockLikeEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.registry.tag.FluidTags;
import net.minecraft.state.property.Properties;
Expand Down Expand Up @@ -241,7 +243,7 @@ protected void writeCustomDataToNbt(NbtCompound compound) {

@Override
protected void readCustomDataFromNbt(NbtCompound compound) {
this.blockState = NbtHelper.toBlockState(compound.getCompound("BlockState"));
this.blockState = NbtHelper.toBlockState(BuiltinRegistries.createWrapperLookup().getWrapperOrThrow(RegistryKeys.BLOCK), compound.getCompound("BlockState"));
this.moveTime = compound.getInt("Time");
if (compound.contains("HurtEntities", 99)) {
this.hurtEntities = compound.getBoolean("HurtEntities");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void tryCraft() {

Optional<TreeTapRecipe> recipe = this.world.getRecipeManager().getFirstMatch(ParadiseLostRecipeTypes.TREE_TAP_RECIPE_TYPE, this, this.world);
if (recipe.isPresent() && world.random.nextInt(recipe.get().getChance()) == 0) {
ItemStack output = recipe.get().craft(this);
ItemStack output = recipe.get().craft(this, world.getRegistryManager());
Block convertBlock = recipe.get().getOutputBlock();
BlockPos attachedPos = this.pos.offset(world.getBlockState(this.pos).get(TreeTapBlock.FACING).getOpposite());
BlockState attachedBlock = world.getBlockState(attachedPos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public void travel(Vec3d movementInput) {
isInAir = false;
}

this.airStrafingSpeed = getFlyingSpeed();
//this.airStrafingSpeed = getFlyingSpeed(); TODO?
if (this.isLogicalSideForUpdatingMovement()) {
this.setMovementSpeed(getMountedMoveSpeed());
super.travel(new Vec3d(f, movementInput.y, g));
Expand All @@ -372,7 +372,7 @@ public void travel(Vec3d movementInput) {

this.updateLimbs(false);
} else {
this.airStrafingSpeed = getFlyingSpeed();
//this.airStrafingSpeed = getFlyingSpeed(); TODO?
super.travel(movementInput);
}
if (getGenes().getRace().legendary() && getVelocity().lengthSquared() > 0.02 && random.nextFloat() < 0.55F) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/net/id/paradiselost/recipe/RecipeHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.id.paradiselost.recipe;

import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtHelper;
import net.minecraft.recipe.ShapedRecipe;
import net.minecraft.util.JsonHelper;

public class RecipeHelper {
// extracted from Incubus Core
public static ItemStack getItemStackWithNbtFromJson(JsonObject json) {
Item item = ShapedRecipe.getItem(json);

int count = JsonHelper.getInt(json, "count", 1);
if (count < 1) {
throw new JsonSyntaxException("Invalid output count: " + count);
}

ItemStack stack = new ItemStack(item, count);
String nbt = JsonHelper.getString(json, "nbt", "");
if(nbt.isEmpty()) {
return stack;
}

try {
NbtCompound compound = NbtHelper.fromNbtProviderString(nbt);
compound.remove("palette");
stack.setNbt(compound);
} catch (CommandSyntaxException e) {
throw new JsonSyntaxException("Invalid output nbt: " + nbt);
}

return stack;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package net.id.paradiselost.recipe;

import com.google.gson.JsonObject;
import net.id.incubus_core.recipe.RecipeParser;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.registry.Registry;

public record TreeTapRecipeSerializer(TreeTapRecipeSerializer.RecipeFactory recipeFactory) implements RecipeSerializer<TreeTapRecipe> {

Expand All @@ -21,9 +20,9 @@ public interface RecipeFactory {
public TreeTapRecipe read(Identifier identifier, JsonObject jsonObject) {
String group = JsonHelper.getString(jsonObject, "group", "");
Ingredient ingredient = Ingredient.fromJson(JsonHelper.getObject(jsonObject, "ingredient"));
Block tappedBlock = Registry.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "tapped_block")));
Block resultBlock = Registry.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "result_block")));
ItemStack output = RecipeParser.getItemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result"));
Block tappedBlock = Registries.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "tapped_block")));
Block resultBlock = Registries.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "result_block")));
ItemStack output = RecipeHelper.getItemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result"));
int chance = JsonHelper.getInt(jsonObject, "chance");

return this.recipeFactory.create(identifier, group, ingredient, output, tappedBlock, resultBlock, chance);
Expand All @@ -33,8 +32,8 @@ public TreeTapRecipe read(Identifier identifier, JsonObject jsonObject) {
public void write(PacketByteBuf packetByteBuf, TreeTapRecipe recipe) {
packetByteBuf.writeString(recipe.group);
recipe.ingredient.write(packetByteBuf);
packetByteBuf.writeIdentifier(Registry.BLOCK.getId(recipe.tappedBlock));
packetByteBuf.writeIdentifier(Registry.BLOCK.getId(recipe.resultBlock));
packetByteBuf.writeIdentifier(Registries.BLOCK.getId(recipe.tappedBlock));
packetByteBuf.writeIdentifier(Registries.BLOCK.getId(recipe.resultBlock));
packetByteBuf.writeItemStack(recipe.output);
packetByteBuf.writeInt(recipe.chance);
}
Expand All @@ -43,8 +42,8 @@ public void write(PacketByteBuf packetByteBuf, TreeTapRecipe recipe) {
public TreeTapRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) {
String group = packetByteBuf.readString();
Ingredient ingredient = Ingredient.fromPacket(packetByteBuf);
Block tappedBlock = Registry.BLOCK.get(packetByteBuf.readIdentifier());
Block resultBlock = Registry.BLOCK.get(packetByteBuf.readIdentifier());
Block tappedBlock = Registries.BLOCK.get(packetByteBuf.readIdentifier());
Block resultBlock = Registries.BLOCK.get(packetByteBuf.readIdentifier());
ItemStack output = packetByteBuf.readItemStack();
int chance = packetByteBuf.readInt();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/id/paradiselost/screen/MoaScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {

@Override
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShader(GameRenderer::getPositionTexProgram);
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
RenderSystem.setShaderTexture(0, TEXTURE);
int x = (width - backgroundWidth) >> 1;
Expand All @@ -57,7 +57,7 @@ protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int
var scale = MinecraftClient.getInstance().getWindow().getScaleFactor();
//RenderSystem.enableScissor(this.x + (int) ((x + 26) * scale), this.y + (int) ((y + 18) * scale), (int) (52 * scale), (int) (52 * scale));
try {
InventoryScreen.drawEntity(x + 51, y + 60, 17, x + 51 - mouseX, y + 25 - mouseY, moa);
InventoryScreen.drawEntity(matrices, x + 51, y + 60, 17, x + 51 - mouseX, y + 25 - mouseY, moa);
} finally {
RenderSystem.disableScissor();
}
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/net/id/paradiselost/screen/ParadiseLostScreens.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,4 @@ private static <T extends ScreenHandler> ScreenHandlerType<T> register(String na
private static <T extends ScreenHandler, S extends HandledScreen<T>> void register(ScreenHandlerType<T> type, ScreenRegistry.Factory<T, S> factory) {
ScreenRegistry.register(type, factory);
}

@Environment(EnvType.CLIENT)
public static void clientInit() {
// Registers the custom slot textures
ClientSpriteRegistryCallback.event(BLOCK_ATLAS_TEXTURE).register((atlas, registry) -> {
for (PreviewSlot.Image value : PreviewSlot.Image.values()) {
registry.register(value.location());
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.id.paradiselost.screen.handler;

import com.mojang.datafixers.util.Pair;
import net.id.paradiselost.ParadiseLost;
import net.id.paradiselost.entities.passive.moa.MoaEntity;
import net.id.paradiselost.mixin.util.SlotAccessor;
import net.id.paradiselost.screen.ParadiseLostScreens;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SaddleItem;
import net.minecraft.screen.EnchantmentScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Identifier;
Expand All @@ -38,7 +40,7 @@ public boolean isValid(int slot, ItemStack stack) {
private final MoaEntity moa;
private final Set<Slot> moaChestSlots;
private boolean enableMoaInventory;

public MoaScreenHandler(int syncId, PlayerInventory playerInventory, Inventory moaInventory, MoaEntity moa) {
super(ParadiseLostScreens.MOA, syncId);
this.moa = moa;
Expand All @@ -56,7 +58,7 @@ public int getMaxItemCount() {

@Override
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(BLOCK_ATLAS_TEXTURE, PreviewSlot.Image.SADDLE.location());
return Pair.of(BLOCK_ATLAS_TEXTURE, ParadiseLost.locate("item/slot/empty_slot_saddle"));
}
}
);
Expand All @@ -78,7 +80,7 @@ public void markDirty() {

@Override
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(BLOCK_ATLAS_TEXTURE, PreviewSlot.Image.CHEST.location());
return Pair.of(BLOCK_ATLAS_TEXTURE, ParadiseLost.locate("item/slot/empty_slot_chest"));
}
}
);
Expand Down Expand Up @@ -128,7 +130,7 @@ private void updateChestState() {
((SlotAccessor) slot).setInventory(inventory);
}
}

@Override
public boolean canUse(PlayerEntity player) {
return player.squaredDistanceTo(moa) <= 64;
Expand All @@ -143,7 +145,7 @@ public MoaEntity moa() {
}

@Override
public ItemStack transferSlot(PlayerEntity player, int sourceSlot) {
public ItemStack quickMove(PlayerEntity player, int sourceSlot) {
ItemStack result = ItemStack.EMPTY;
if (!moa.hasChest()) return result;
Slot slot = slots.get(sourceSlot);
Expand Down
26 changes: 4 additions & 22 deletions src/main/java/net/id/paradiselost/screen/slot/PreviewSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,17 @@
* A slot with a custom item "preview", like the armor slots in the Player's inventory.
*/
public class PreviewSlot extends Slot {
private final Image image;
private final Identifier image;

public PreviewSlot(Image image, Inventory inventory, int index, int x, int y) {
public PreviewSlot(Identifier image, Inventory inventory, int index, int x, int y) {
super(inventory, index, x, y);
this.image = image;
}

@Environment(EnvType.CLIENT)
@Override
public Pair<Identifier, Identifier> getBackgroundSprite() {
return Pair.of(BLOCK_ATLAS_TEXTURE, image.location);
}

public enum Image {
CHEST("item/slot/chest"),
SADDLE("item/slot/saddle");

private final Identifier location;

Image(String location) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
this.location = locate(location);
} else {
this.location = null;
}
}

public Identifier location() {
return location;
}
return Pair.of(BLOCK_ATLAS_TEXTURE, image);
}

}
Loading

0 comments on commit 2cb5058

Please sign in to comment.