Skip to content

Commit 339ef15

Browse files
committed
release1.0
1 parent 6ac9d5b commit 339ef15

File tree

7 files changed

+28
-54
lines changed

7 files changed

+28
-54
lines changed

src/main/java/net/dl909/crafter/Crafter.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import net.minecraft.registry.Registry;
2020
import net.minecraft.screen.ScreenHandlerType;
2121
import net.minecraft.util.Identifier;
22-
import net.minecraft.util.math.BlockPos;
2322

2423
public class Crafter implements ModInitializer {
2524

@@ -40,7 +39,7 @@ public void onInitialize() {
4039
return;
4140
}
4241
Object object = player.currentScreenHandler;
43-
if (object instanceof CrafterScreenHandler && ((CrafterScreenHandler)object).getInputInventory() instanceof CrafterBlockEntity) {
42+
if (object instanceof CrafterScreenHandler && (object = ((CrafterScreenHandler)object).getInputInventory()) instanceof CrafterBlockEntity) {
4443
CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity)object;
4544
crafterBlockEntity.setSlotEnabled(slotId, enabled);
4645
}

src/main/java/net/dl909/crafter/block/CrafterBlock.java

+14-23
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,12 @@
4141
public class CrafterBlock extends BlockWithEntity implements BlockEntityProvider {
4242
public static final BooleanProperty TRIGGERED;
4343
public static final BooleanProperty CRAFTING;
44-
private static final int field_46802 = 6;
45-
private static final int TRIGGER_DELAY = 4;
4644
private static final RecipeCache recipeCache = new RecipeCache(10);
47-
private static final int field_50015 = 17;
4845
private static final EnumProperty<JigsawOrientation> ORIENTATION;
4946

5047
public CrafterBlock(Settings settings) {
5148
super(settings);
52-
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(ORIENTATION, JigsawOrientation.NORTH_UP)).with(TRIGGERED, false)).with(CRAFTING, false));
49+
this.setDefaultState(this.stateManager.getDefaultState().with(ORIENTATION, JigsawOrientation.NORTH_UP).with(TRIGGERED, false).with(CRAFTING, false));
5350
}
5451

5552
@Override
@@ -59,8 +56,7 @@ public boolean hasComparatorOutput(BlockState state) {
5956
@Override
6057
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
6158
BlockEntity blockEntity = world.getBlockEntity(pos);
62-
if (blockEntity instanceof CrafterBlockEntity) {
63-
CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity)blockEntity;
59+
if (blockEntity instanceof CrafterBlockEntity crafterBlockEntity) {
6460
return crafterBlockEntity.getComparatorOutput();
6561
}
6662
return 0;
@@ -72,10 +68,10 @@ public void neighborUpdate(BlockState state, World world, BlockPos pos, Block so
7268
BlockEntity blockEntity = world.getBlockEntity(pos);
7369
if (bl && !bl2) {
7470
world.scheduleBlockTick(pos, this, 4);
75-
world.setBlockState(pos, (BlockState)state.with(TRIGGERED, true), Block.NOTIFY_LISTENERS);
71+
world.setBlockState(pos, state.with(TRIGGERED, true), Block.NOTIFY_LISTENERS);
7672
this.setTriggered(blockEntity, true);
7773
} else if (!bl && bl2) {
78-
world.setBlockState(pos, (BlockState)((BlockState)state.with(TRIGGERED, false)).with(CRAFTING, false), Block.NOTIFY_LISTENERS);
74+
world.setBlockState(pos, state.with(TRIGGERED, false).with(CRAFTING, false), Block.NOTIFY_LISTENERS);
7975
this.setTriggered(blockEntity, false);
8076
}
8177
}
@@ -91,8 +87,7 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block
9187
}
9288

9389
private void setTriggered(@Nullable BlockEntity blockEntity, boolean triggered) {
94-
if (blockEntity instanceof CrafterBlockEntity) {
95-
CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity)blockEntity;
90+
if (blockEntity instanceof CrafterBlockEntity crafterBlockEntity) {
9691
crafterBlockEntity.setTriggered(triggered);
9792
}
9893
}
@@ -101,23 +96,22 @@ private void setTriggered(@Nullable BlockEntity blockEntity, boolean triggered)
10196
@Override
10297
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
10398
CrafterBlockEntity crafterBlockEntity = new CrafterBlockEntity(pos, state);
104-
crafterBlockEntity.setTriggered(state.contains(TRIGGERED) && state.get(TRIGGERED) != false);
99+
crafterBlockEntity.setTriggered(state.contains(TRIGGERED) && state.get(TRIGGERED));
105100
return new CrafterBlockEntity(pos,state);
106101
}
107102
@Override
108103
public BlockState getPlacementState(ItemPlacementContext ctx) {
109104
Direction direction = ctx.getPlayerLookDirection().getOpposite();
110105
Direction direction2 = switch (direction) {
111-
default -> throw new RuntimeException(null, null);
112106
case DOWN -> ctx.getHorizontalPlayerFacing().getOpposite();
113107
case UP -> ctx.getHorizontalPlayerFacing();
114108
case NORTH, SOUTH, WEST, EAST -> Direction.UP;
115109
};
116-
return (BlockState)((BlockState)this.getDefaultState().with(ORIENTATION, JigsawOrientation.byDirections(direction, direction2))).with(TRIGGERED, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()));
110+
return this.getDefaultState().with(ORIENTATION, JigsawOrientation.byDirections(direction, direction2)).with(TRIGGERED, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()));
117111
}
118112
@Override
119113
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
120-
if (state.get(TRIGGERED).booleanValue()) {
114+
if (state.get(TRIGGERED)) {
121115
world.scheduleBlockTick(pos, this, 4);
122116
}
123117
}
@@ -128,8 +122,7 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
128122
return;
129123
}
130124
BlockEntity blockEntity = world.getBlockEntity(pos);
131-
if (blockEntity instanceof Inventory) {
132-
Inventory inventory = (Inventory)((Object)blockEntity);
125+
if (blockEntity instanceof Inventory inventory) {
133126
ItemScatterer.spawn(world, pos, inventory);
134127
world.updateComparators(pos, state.getBlock());
135128
}
@@ -152,10 +145,9 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
152145
}
153146
protected void craft(BlockState state, ServerWorld world, BlockPos pos){
154147
BlockEntity blockEntity = world.getBlockEntity(pos);
155-
if (!(blockEntity instanceof CrafterBlockEntity)) {
148+
if (!(blockEntity instanceof CrafterBlockEntity crafterBlockEntity)) {
156149
return;
157150
}
158-
CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity)blockEntity;
159151
CraftingInventory craftingInventory = new CraftingInventory(new VoidScreenHandler(),3,3);
160152
Optional<CraftingRecipe> optional = CrafterBlock.getCraftingRecipe(world, crafterBlockEntity);
161153
if (optional.isEmpty()) {
@@ -169,7 +161,7 @@ protected void craft(BlockState state, ServerWorld world, BlockPos pos){
169161
return;
170162
}
171163
crafterBlockEntity.setCraftingTicksRemaining(6);
172-
world.setBlockState(pos, (BlockState)state.with(CRAFTING, true), Block.NOTIFY_LISTENERS);
164+
world.setBlockState(pos, state.with(CRAFTING, true), Block.NOTIFY_LISTENERS);
173165
itemStack.getItem().onCraft(itemStack,world,null);
174166
this.transferOrSpawnStack(world, pos, crafterBlockEntity, itemStack, state);
175167
/*
@@ -202,8 +194,7 @@ private void transferOrSpawnStack(ServerWorld world, BlockPos pos, CrafterBlockE
202194
itemStack.decrement(1);
203195
}
204196
} else if (inventory != null) {
205-
int i;
206-
while (!itemStack.isEmpty() && (i = itemStack.getCount()) != (itemStack = HopperBlockEntity.transfer(blockEntity, inventory, itemStack, direction.getOpposite())).getCount()) {
197+
while (!itemStack.isEmpty() && itemStack.getCount() != (itemStack = HopperBlockEntity.transfer(blockEntity, inventory, itemStack, direction.getOpposite())).getCount()) {
207198
}
208199
}
209200
if (!itemStack.isEmpty()) {
@@ -219,12 +210,12 @@ public BlockRenderType getRenderType(BlockState state) {
219210

220211
@Override
221212
public BlockState rotate(BlockState state, BlockRotation rotation) {
222-
return (BlockState)state.with(ORIENTATION, rotation.getDirectionTransformation().mapJigsawOrientation(state.get(ORIENTATION)));
213+
return state.with(ORIENTATION, rotation.getDirectionTransformation().mapJigsawOrientation(state.get(ORIENTATION)));
223214
}
224215

225216
@Override
226217
public BlockState mirror(BlockState state, BlockMirror mirror) {
227-
return (BlockState)state.with(ORIENTATION, mirror.getDirectionTransformation().mapJigsawOrientation(state.get(ORIENTATION)));
218+
return state.with(ORIENTATION, mirror.getDirectionTransformation().mapJigsawOrientation(state.get(ORIENTATION)));
228219
}
229220

230221
@Override

src/main/java/net/dl909/crafter/block/CrafterBlockEntity.java

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.dl909.crafter.block;
22

3-
import com.google.common.annotations.VisibleForTesting;
43
import it.unimi.dsi.fastutil.ints.IntArrayList;
54
import it.unimi.dsi.fastutil.ints.IntList;
65
import net.dl909.crafter.Crafter;
@@ -148,10 +147,7 @@ public void readNbt(NbtCompound nbt) {
148147
this.propertyDelegate.set(i, 0);
149148
}
150149

151-
int var5 = is.length;
152-
153-
for(int var6 = 0; var6 < var5; ++var6) {
154-
int j = is[var6];
150+
for (int j : is) {
155151
if (this.canToggleSlot(j)) {
156152
this.propertyDelegate.set(j, 1);
157153
}
@@ -227,15 +223,9 @@ public DefaultedList<ItemStack> getHeldStacks() {
227223
return this.inputStacks;
228224
}
229225

230-
public void setHeldStacks(DefaultedList<ItemStack> inventory) {
231-
this.inputStacks = inventory;
232-
}
233-
234226
public void provideRecipeInputs(RecipeMatcher finder) {
235-
Iterator<ItemStack> var2 = this.inputStacks.iterator();
236227

237-
while(var2.hasNext()) {
238-
ItemStack itemStack = var2.next();
228+
for (ItemStack itemStack : this.inputStacks) {
239229
finder.addUnenchantedInput(itemStack);
240230
}
241231

@@ -261,17 +251,12 @@ public void setTriggered(boolean triggered) {
261251
this.propertyDelegate.set(9, triggered ? 1 : 0);
262252
}
263253

264-
@VisibleForTesting
265-
public boolean isTriggered() {
266-
return this.propertyDelegate.get(9) == 1;
267-
}
268-
269254
public static void tickCrafting(World world, BlockPos pos, BlockState state, CrafterBlockEntity blockEntity) {
270255
int i = blockEntity.craftingTicksRemaining - 1;
271256
if (i >= 0) {
272257
blockEntity.craftingTicksRemaining = i;
273258
if (i == 0) {
274-
world.setBlockState(pos, (BlockState)state.with(CrafterBlock.CRAFTING, false), 3);
259+
world.setBlockState(pos, state.with(CrafterBlock.CRAFTING, false), 3);
275260
}
276261

277262
}

src/main/java/net/dl909/crafter/client/gui/screen/ingame/CrafterScreen.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import net.minecraft.network.PacketByteBuf;
1919
import net.minecraft.screen.slot.Slot;
2020
import net.minecraft.screen.slot.SlotActionType;
21-
import net.minecraft.sound.SoundEvent;
2221
import net.minecraft.sound.SoundEvents;
2322
import net.minecraft.text.Text;
2423
import net.minecraft.util.Identifier;
@@ -46,16 +45,16 @@ protected void onMouseClick(Slot slot, int slotId, int button, SlotActionType ac
4645
if (slot instanceof CrafterInputSlot && !slot.hasStack() && !this.player.isSpectator()) {
4746
switch (actionType) {
4847
case PICKUP:
49-
if (((CrafterScreenHandler)this.handler).isSlotDisabled(slotId)) {
48+
if (this.handler.isSlotDisabled(slotId)) {
5049
this.enableSlot(slotId);
5150

52-
} else if (((CrafterScreenHandler)this.handler).getCursorStack().isEmpty()) {
51+
} else if (this.handler.getCursorStack().isEmpty()) {
5352
this.disableSlot(slotId);
5453
}
5554
break;
5655
case SWAP:
5756
ItemStack itemStack = this.player.getInventory().getStack(button);
58-
if (((CrafterScreenHandler)this.handler).isSlotDisabled(slotId) && !itemStack.isEmpty()) {
57+
if (this.handler.isSlotDisabled(slotId) && !itemStack.isEmpty()) {
5958
this.enableSlot(slotId);
6059
}
6160
}
@@ -72,15 +71,14 @@ private void disableSlot(int slotId) {
7271
}
7372

7473
private void setSlotEnabled(int slotId, boolean enabled) {
75-
((CrafterScreenHandler)this.handler).setSlotEnabled(slotId, enabled);
74+
this.handler.setSlotEnabled(slotId, enabled);
7675
float f = enabled ? 1.0F : 0.75F;
7776
PacketByteBuf buf = PacketByteBufs.create();
78-
buf.writeBlockPos(this.handler.pos);
7977
buf.writeInt(slotId);
8078
buf.writeInt(this.handler.syncId);
8179
buf.writeBoolean(enabled);
8280
ClientPlayNetworking.send(Crafter.SLOT_CHANGE_STATE, buf);
83-
this.player.playSound((SoundEvent)SoundEvents.UI_BUTTON_CLICK.value(), 0.4F, f);
81+
this.player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.4F, f);
8482
}
8583

8684
@Override
@@ -95,7 +93,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
9593
}
9694
drawArrowTexture(matrices);
9795
drawMouseoverTooltip(matrices, mouseX, mouseY);
98-
if (this.focusedSlot instanceof CrafterInputSlot && !((CrafterScreenHandler)this.handler).isSlotDisabled(this.focusedSlot.id) && ((CrafterScreenHandler)this.handler).getCursorStack().isEmpty() && !this.focusedSlot.hasStack() && !this.player.isSpectator()) {
96+
if (this.focusedSlot instanceof CrafterInputSlot && !this.handler.isSlotDisabled(this.focusedSlot.id) && this.handler.getCursorStack().isEmpty() && !this.focusedSlot.hasStack() && !this.player.isSpectator()) {
9997
this.renderTooltip(matrices, TOGGLEABLE_SLOT_TEXT, mouseX, mouseY);
10098
}
10199
}

src/main/java/net/dl909/crafter/recipe/RecipeCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public Optional<CraftingRecipe> getRecipe(World world, CrafterBlockEntity recipe
5151
private void validateRecipeManager(World world) {
5252
RecipeManager recipeManager = world.getRecipeManager();
5353
if (recipeManager != this.recipeManagerRef.get()) {
54-
this.recipeManagerRef = new WeakReference<RecipeManager>(recipeManager);
54+
this.recipeManagerRef = new WeakReference<>(recipeManager);
5555
Arrays.fill(this.cache, null);
5656
}
5757
}

src/main/java/net/dl909/crafter/screen/CrafterScreenHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public boolean isSlotDisabled(int slot) {
119119
public ItemStack quickMove(PlayerEntity player, int invSlot) {
120120
ItemStack newStack = ItemStack.EMPTY;
121121
Slot slot = this.slots.get(invSlot);
122-
if (slot != null && slot.hasStack()) {
122+
if (slot.hasStack()) {
123123
ItemStack originalStack = slot.getStack();
124124
newStack = originalStack.copy();
125125
if (invSlot < this.inputInventory.size()) {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"block.minecraft.crafter": "crafter",
3-
"gui.toggleable_slot": "Click to disable slot"
3+
"gui.toggleable_slot": "Click to disable slot",
4+
"container.crafter": "crafter"
45
}

0 commit comments

Comments
 (0)