Skip to content

Commit

Permalink
fix item rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuzss committed Feb 5, 2024
1 parent d7bcdce commit 6451e14
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
4 changes: 4 additions & 0 deletions 1.20.4/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v20.4.1-1.20.4] - 2024-02-05
### Fixed
- Fix rendered crafting tables contents failing to rotate towards the closest player

## [v20.4.0-1.20.4] - 2024-01-27
- Rewritten for Minecraft 1.20.4
- All modded crafting tables are supported automatically, use `visualworkbench:unaltered_workbenches` for individual exclusions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public VisualCraftingMenu(int id, Inventory inventory, CraftingTableBlockEntity
this.craftSlots = new VisualTransientCraftingContainer(this, 3, 3, blockEntity.getItems(), blockEntity);
this.resultSlots = new VisualResultContainer(blockEntity.getResultItems(), blockEntity);
this.setCraftingSlotsContainer();
// always update recipe output when opening menu, otherwise could be missing or outdated if the block entity didn't save it correctly
this.refreshRecipeResult();
}

private void setCraftingSlotsContainer() {
Expand All @@ -31,15 +33,13 @@ private void setCraftingSlotsContainer() {
}
}

@Override
public MenuType<?> getType() {
return ModRegistry.CRAFTING_MENU_TYPE.value();
private void refreshRecipeResult() {
this.slotsChanged(this.craftSlots);
}

@Override
public boolean stillValid(Player player) {
// craft slots are extended to forward this to the block entity, normally in vanilla this would always return true
return this.craftSlots.stillValid(player);
public MenuType<?> getType() {
return ModRegistry.CRAFTING_MENU_TYPE.value();
}

@Override
Expand All @@ -50,4 +50,10 @@ public void removed(Player player) {
super.removed(player);
this.access = containerLevelAccess;
}

@Override
public boolean stillValid(Player player) {
// craft slots are extended to forward this to the block entity, normally in vanilla this would always return true
return this.craftSlots.stillValid(player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public VisualResultContainer(NonNullList<ItemStack> items, Container container)
@Override
public ItemStack removeItem(int slot, int amount) {
ItemStack result = ContainerHelper.removeItem(this.itemStacks, slot, amount);
if (!result.isEmpty()) this.container.setChanged();
if (!result.isEmpty()) this.setChanged();
return result;
}

@Override
public void setItem(int slot, ItemStack stack) {
super.setItem(slot, stack);
this.setChanged();
}

@Override
public void setChanged() {
super.setChanged();
this.container.setChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ public VisualTransientCraftingContainer(AbstractContainerMenu menu, int width, i
@Override
public ItemStack removeItem(int slot, int amount) {
ItemStack itemStack = super.removeItem(slot, amount);
if (!itemStack.isEmpty()) this.container.setChanged();
if (!itemStack.isEmpty()) this.setChanged();
return itemStack;
}

@Override
public void setItem(int slot, ItemStack stack) {
super.setItem(slot, stack);
this.setChanged();
}

@Override
public void setChanged() {
super.setChanged();
this.container.setChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
public class CraftingTableAnimationController {
private final Vec3 position;

public int ticks;
public float currentAngle;
public float nextAngle;
Expand All @@ -45,7 +44,7 @@ private void setPlayerAngle(Level level) {
Player player;
if (VisualWorkbench.CONFIG.get(ClientConfig.class).rotateIngredients != ClientConfig.RotateIngredients.NEVER) {
player = level.getNearestPlayer(this.position.x(), this.position.y(), this.position.z(), 3.0, (Entity entity) -> {
if (!entity.isSpectator()) {
if (entity.isSpectator()) {
return false;
} else if (VisualWorkbench.CONFIG.get(ClientConfig.class).rotateIngredients == ClientConfig.RotateIngredients.CLOSEST_PLAYER) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fuzs.puzzleslib.api.block.v1.entity.TickingBlockEntity;
import fuzs.puzzleslib.api.container.v1.ContainerSerializationHelper;
import fuzs.visualworkbench.VisualWorkbench;
import fuzs.visualworkbench.init.ModRegistry;
import fuzs.visualworkbench.world.inventory.VisualCraftingMenu;
import net.minecraft.core.BlockPos;
Expand All @@ -22,12 +23,12 @@
import org.jetbrains.annotations.Nullable;

public class CraftingTableBlockEntity extends RandomizableContainerBlockEntity implements TickingBlockEntity, WorkbenchVisualsProvider {
public static final MutableComponent CRAFTING_COMPONENT = Component.translatable("container.crafting");
public static final String TAG_RESULT = "Result";
public static final MutableComponent COMPONENT_CRAFTING = Component.translatable("container.crafting");
public static final String TAG_RESULT = VisualWorkbench.id("result").toString();

private final CraftingTableAnimationController animationController;
private NonNullList<ItemStack> items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
private NonNullList<ItemStack> resultItems = NonNullList.withSize(1, ItemStack.EMPTY);
private final NonNullList<ItemStack> items = NonNullList.withSize(9, ItemStack.EMPTY);
private final NonNullList<ItemStack> resultItems = NonNullList.withSize(1, ItemStack.EMPTY);

public CraftingTableBlockEntity(BlockPos pos, BlockState blockState) {
super(ModRegistry.CRAFTING_TABLE_BLOCK_ENTITY.value(), pos, blockState);
Expand All @@ -37,8 +38,8 @@ public CraftingTableBlockEntity(BlockPos pos, BlockState blockState) {
@Override
public void load(CompoundTag tag) {
super.load(tag);
this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
this.resultItems = NonNullList.withSize(1, ItemStack.EMPTY);
this.items.clear();
this.resultItems.clear();
if (!this.tryLoadLootTable(tag)) {
ContainerHelper.loadAllItems(tag, this.items);
ContainerSerializationHelper.loadAllItems(TAG_RESULT, tag, this.resultItems);
Expand Down Expand Up @@ -80,12 +81,13 @@ public NonNullList<ItemStack> getItems() {

@Override
protected void setItems(NonNullList<ItemStack> itemStacks) {
this.items = itemStacks;
// why does this event exist...
throw new UnsupportedOperationException();
}

@Override
protected Component getDefaultName() {
return CRAFTING_COMPONENT;
return COMPONENT_CRAFTING;
}

@Override
Expand All @@ -95,7 +97,7 @@ protected AbstractContainerMenu createMenu(int containerId, Inventory inventory)

@Override
public int getContainerSize() {
return 9;
return this.items.size();
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions 1.20.4/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ copyBuildJar=true
# Mod Attributes
modId=visualworkbench
modName=Visual Workbench
modVersion=20.4.0
modVersion=20.4.1
modAuthor=Fuzs
modDescription=Items stay inside crafting tables and are also rendered on top. It's really fancy!
modLicense=MPL-2.0
Expand All @@ -19,9 +19,9 @@ modForgeDisplayTest=MATCH_VERSION
modFabricEnvironment=*

# Version Catalog
dependenciesVersionCatalog=1.20.4-v14
dependenciesPuzzlesLibVersion=20.4.9
dependenciesMinPuzzlesLibVersion=20.4.9
dependenciesVersionCatalog=1.20.4-v19
#dependenciesPuzzlesLibVersion=20.4.9
#dependenciesMinPuzzlesLibVersion=20.4.9

# Mod Publishing
projectReleaseType=release
Expand Down

0 comments on commit 6451e14

Please sign in to comment.