41
41
public class CrafterBlock extends BlockWithEntity implements BlockEntityProvider {
42
42
public static final BooleanProperty TRIGGERED ;
43
43
public static final BooleanProperty CRAFTING ;
44
- private static final int field_46802 = 6 ;
45
- private static final int TRIGGER_DELAY = 4 ;
46
44
private static final RecipeCache recipeCache = new RecipeCache (10 );
47
- private static final int field_50015 = 17 ;
48
45
private static final EnumProperty <JigsawOrientation > ORIENTATION ;
49
46
50
47
public CrafterBlock (Settings settings ) {
51
48
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 ));
53
50
}
54
51
55
52
@ Override
@@ -59,8 +56,7 @@ public boolean hasComparatorOutput(BlockState state) {
59
56
@ Override
60
57
public int getComparatorOutput (BlockState state , World world , BlockPos pos ) {
61
58
BlockEntity blockEntity = world .getBlockEntity (pos );
62
- if (blockEntity instanceof CrafterBlockEntity ) {
63
- CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity )blockEntity ;
59
+ if (blockEntity instanceof CrafterBlockEntity crafterBlockEntity ) {
64
60
return crafterBlockEntity .getComparatorOutput ();
65
61
}
66
62
return 0 ;
@@ -72,10 +68,10 @@ public void neighborUpdate(BlockState state, World world, BlockPos pos, Block so
72
68
BlockEntity blockEntity = world .getBlockEntity (pos );
73
69
if (bl && !bl2 ) {
74
70
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 );
76
72
this .setTriggered (blockEntity , true );
77
73
} 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 );
79
75
this .setTriggered (blockEntity , false );
80
76
}
81
77
}
@@ -91,8 +87,7 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block
91
87
}
92
88
93
89
private void setTriggered (@ Nullable BlockEntity blockEntity , boolean triggered ) {
94
- if (blockEntity instanceof CrafterBlockEntity ) {
95
- CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity )blockEntity ;
90
+ if (blockEntity instanceof CrafterBlockEntity crafterBlockEntity ) {
96
91
crafterBlockEntity .setTriggered (triggered );
97
92
}
98
93
}
@@ -101,23 +96,22 @@ private void setTriggered(@Nullable BlockEntity blockEntity, boolean triggered)
101
96
@ Override
102
97
public BlockEntity createBlockEntity (BlockPos pos , BlockState state ) {
103
98
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 ));
105
100
return new CrafterBlockEntity (pos ,state );
106
101
}
107
102
@ Override
108
103
public BlockState getPlacementState (ItemPlacementContext ctx ) {
109
104
Direction direction = ctx .getPlayerLookDirection ().getOpposite ();
110
105
Direction direction2 = switch (direction ) {
111
- default -> throw new RuntimeException (null , null );
112
106
case DOWN -> ctx .getHorizontalPlayerFacing ().getOpposite ();
113
107
case UP -> ctx .getHorizontalPlayerFacing ();
114
108
case NORTH , SOUTH , WEST , EAST -> Direction .UP ;
115
109
};
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 ()));
117
111
}
118
112
@ Override
119
113
public void onPlaced (World world , BlockPos pos , BlockState state , LivingEntity placer , ItemStack itemStack ) {
120
- if (state .get (TRIGGERED ). booleanValue () ) {
114
+ if (state .get (TRIGGERED )) {
121
115
world .scheduleBlockTick (pos , this , 4 );
122
116
}
123
117
}
@@ -128,8 +122,7 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
128
122
return ;
129
123
}
130
124
BlockEntity blockEntity = world .getBlockEntity (pos );
131
- if (blockEntity instanceof Inventory ) {
132
- Inventory inventory = (Inventory )((Object )blockEntity );
125
+ if (blockEntity instanceof Inventory inventory ) {
133
126
ItemScatterer .spawn (world , pos , inventory );
134
127
world .updateComparators (pos , state .getBlock ());
135
128
}
@@ -152,10 +145,9 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
152
145
}
153
146
protected void craft (BlockState state , ServerWorld world , BlockPos pos ){
154
147
BlockEntity blockEntity = world .getBlockEntity (pos );
155
- if (!(blockEntity instanceof CrafterBlockEntity )) {
148
+ if (!(blockEntity instanceof CrafterBlockEntity crafterBlockEntity )) {
156
149
return ;
157
150
}
158
- CrafterBlockEntity crafterBlockEntity = (CrafterBlockEntity )blockEntity ;
159
151
CraftingInventory craftingInventory = new CraftingInventory (new VoidScreenHandler (),3 ,3 );
160
152
Optional <CraftingRecipe > optional = CrafterBlock .getCraftingRecipe (world , crafterBlockEntity );
161
153
if (optional .isEmpty ()) {
@@ -169,7 +161,7 @@ protected void craft(BlockState state, ServerWorld world, BlockPos pos){
169
161
return ;
170
162
}
171
163
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 );
173
165
itemStack .getItem ().onCraft (itemStack ,world ,null );
174
166
this .transferOrSpawnStack (world , pos , crafterBlockEntity , itemStack , state );
175
167
/*
@@ -202,8 +194,7 @@ private void transferOrSpawnStack(ServerWorld world, BlockPos pos, CrafterBlockE
202
194
itemStack .decrement (1 );
203
195
}
204
196
} 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 ()) {
207
198
}
208
199
}
209
200
if (!itemStack .isEmpty ()) {
@@ -219,12 +210,12 @@ public BlockRenderType getRenderType(BlockState state) {
219
210
220
211
@ Override
221
212
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 )));
223
214
}
224
215
225
216
@ Override
226
217
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 )));
228
219
}
229
220
230
221
@ Override
0 commit comments