Skip to content

Commit 7f198d2

Browse files
committed
🐺🔧
1 parent d59ee1d commit 7f198d2

7 files changed

Lines changed: 200 additions & 4 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ loader_version_range=[1,)
1616
mod_id=futurefood
1717
mod_name=Future Food
1818
mod_license=MIT
19-
mod_version=1.0.1
19+
mod_version=1.0.2
2020
mod_group_id=top.ctnstudio.futurefood
2121
mod_authors=
2222
mod_description=

src/main/java/top/ctnstudio/futurefood/common/block/tile/BaseEnergyStorageBlockEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
1313
import net.minecraft.server.level.ServerLevel;
1414
import net.minecraft.world.MenuProvider;
15+
import net.minecraft.world.WorldlyContainer;
1516
import net.minecraft.world.entity.player.Inventory;
1617
import net.minecraft.world.entity.player.Player;
1718
import net.minecraft.world.inventory.AbstractContainerMenu;
@@ -43,7 +44,7 @@
4344
import java.util.Objects;
4445

4546
public abstract class BaseEnergyStorageBlockEntity<T extends BasicEnergyMenu> extends ModBlockEntity
46-
implements MenuProvider, IItemStackModify, IEnergyStorageModify {
47+
implements MenuProvider, IItemStackModify, IEnergyStorageModify, WorldlyContainer {
4748

4849
protected final ModEnergyStorage energyStorage;
4950
protected final ModItemStackHandler itemHandler;

src/main/java/top/ctnstudio/futurefood/common/block/tile/BatteryBlockEntity.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package top.ctnstudio.futurefood.common.block.tile;
22

33
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
45
import net.minecraft.core.HolderLookup;
56
import net.minecraft.nbt.CompoundTag;
67
import net.minecraft.world.entity.player.Inventory;
78
import net.minecraft.world.entity.player.Player;
9+
import net.minecraft.world.item.ItemStack;
810
import net.minecraft.world.level.Level;
911
import net.minecraft.world.level.block.state.BlockState;
1012
import org.jetbrains.annotations.NotNull;
@@ -72,4 +74,62 @@ protected void saveAdditional(CompoundTag nbt, HolderLookup.Provider provider) {
7274
public boolean isInfinite() {
7375
return isInfinite;
7476
}
77+
78+
@Override
79+
public int[] getSlotsForFace(Direction direction) {
80+
return new int[]{1};
81+
}
82+
83+
@Override
84+
public boolean canPlaceItemThroughFace(int i, ItemStack itemStack, @Nullable Direction direction) {
85+
return true;
86+
}
87+
88+
@Override
89+
public boolean canTakeItemThroughFace(int i, ItemStack itemStack, Direction direction) {
90+
return true;
91+
}
92+
93+
@Override
94+
public int getContainerSize() {
95+
return this.itemHandler.getSlots();
96+
}
97+
98+
@Override
99+
public boolean isEmpty() {
100+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
101+
if (!this.itemHandler.getStackInSlot(i).isEmpty()) {
102+
return false;
103+
}
104+
}
105+
106+
return true;
107+
}
108+
109+
@Override
110+
public ItemStack getItem(int i) {
111+
return this.itemHandler.getStackInSlot(i);
112+
}
113+
114+
@Override
115+
public ItemStack removeItem(int i, int i1) {
116+
return this.itemHandler.extractItem(i, i1, false);
117+
}
118+
119+
@Override
120+
public ItemStack removeItemNoUpdate(int i) {
121+
return this.itemHandler.extractItem(i, i, false);
122+
}
123+
124+
@Override
125+
public void setItem(int i, ItemStack itemStack) {
126+
this.itemHandler.setStackInSlot(i, itemStack);
127+
}
128+
129+
@Override
130+
public void clearContent() {
131+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
132+
this.itemHandler.setStackInSlot(i, ItemStack.EMPTY);
133+
}
134+
}
75135
}

src/main/java/top/ctnstudio/futurefood/common/block/tile/GluttonyBlockEntity.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package top.ctnstudio.futurefood.common.block.tile;
22

33
import net.minecraft.core.BlockPos;
4+
import net.minecraft.core.Direction;
45
import net.minecraft.core.HolderLookup;
56
import net.minecraft.core.component.DataComponents;
67
import net.minecraft.nbt.CompoundTag;
@@ -227,6 +228,71 @@ protected void saveAdditional(CompoundTag nbt, HolderLookup.Provider provider) {
227228
return new GluttonyMenu(containerId, playerInventory, itemHandler, energyData, workProgress);
228229
}
229230

231+
@Override
232+
public int[] getSlotsForFace(Direction direction) {
233+
if (direction == Direction.DOWN) {
234+
return new int[] { 0 };
235+
} else if (direction == Direction.UP) {
236+
return new int[] { 1 };
237+
}
238+
239+
return new int[] { 2 };
240+
}
241+
242+
@Override
243+
public boolean canPlaceItemThroughFace(int i, ItemStack itemStack, @Nullable Direction direction) {
244+
// TODO true 改成检查 ItemStack 可以存储电力。
245+
return i != 2 && (direction == Direction.UP || true);
246+
}
247+
248+
@Override
249+
public boolean canTakeItemThroughFace(int i, ItemStack itemStack, Direction direction) {
250+
return direction == Direction.DOWN && i == 2;
251+
}
252+
253+
@Override
254+
public int getContainerSize() {
255+
return this.itemHandler.getSlots();
256+
}
257+
258+
@Override
259+
public boolean isEmpty() {
260+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
261+
if (!this.itemHandler.getStackInSlot(i).isEmpty()) {
262+
return false;
263+
}
264+
}
265+
266+
return true;
267+
}
268+
269+
@Override
270+
public ItemStack getItem(int i) {
271+
return this.itemHandler.getStackInSlot(i);
272+
}
273+
274+
@Override
275+
public ItemStack removeItem(int i, int i1) {
276+
return this.itemHandler.extractItem(i, i1, false);
277+
}
278+
279+
@Override
280+
public ItemStack removeItemNoUpdate(int i) {
281+
return this.itemHandler.extractItem(i, i, false);
282+
}
283+
284+
@Override
285+
public void setItem(int i, ItemStack itemStack) {
286+
this.itemHandler.setStackInSlot(i, itemStack);
287+
}
288+
289+
@Override
290+
public void clearContent() {
291+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
292+
this.itemHandler.setStackInSlot(i, ItemStack.EMPTY);
293+
}
294+
}
295+
230296
public record Data(GluttonyBlockEntity blockEntity) implements ContainerData {
231297
@Override
232298
public int get(int index) {

src/main/java/top/ctnstudio/futurefood/common/block/tile/ParticleColliderBlockEntity.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,73 @@ protected void saveAdditional(CompoundTag nbt, HolderLookup.Provider provider) {
115115
return new ParticleColliderMenu(containerId, playerInventory, itemHandler, energyData, workProgress);
116116
}
117117

118+
119+
// TODO - 还没做完
120+
@Override
121+
public int[] getSlotsForFace(Direction direction) {
122+
if (direction == Direction.DOWN) {
123+
return new int[] { 0 };
124+
} else if (direction == Direction.UP) {
125+
return new int[] { 1 };
126+
}
127+
128+
return new int[] { 2 };
129+
}
130+
131+
@Override
132+
public boolean canPlaceItemThroughFace(int i, ItemStack itemStack, @Nullable Direction direction) {
133+
// TODO true 改成检查 ItemStack 可以存储电力。
134+
return i != 2 && (direction == Direction.UP || true);
135+
}
136+
137+
@Override
138+
public boolean canTakeItemThroughFace(int i, ItemStack itemStack, Direction direction) {
139+
return direction == Direction.DOWN && i == 2;
140+
}
141+
142+
@Override
143+
public int getContainerSize() {
144+
return this.itemHandler.getSlots();
145+
}
146+
147+
@Override
148+
public boolean isEmpty() {
149+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
150+
if (!this.itemHandler.getStackInSlot(i).isEmpty()) {
151+
return false;
152+
}
153+
}
154+
155+
return true;
156+
}
157+
158+
@Override
159+
public ItemStack getItem(int i) {
160+
return this.itemHandler.getStackInSlot(i);
161+
}
162+
163+
@Override
164+
public ItemStack removeItem(int i, int i1) {
165+
return this.itemHandler.extractItem(i, i1, false);
166+
}
167+
168+
@Override
169+
public ItemStack removeItemNoUpdate(int i) {
170+
return this.itemHandler.extractItem(i, i, false);
171+
}
172+
173+
@Override
174+
public void setItem(int i, ItemStack itemStack) {
175+
this.itemHandler.setStackInSlot(i, itemStack);
176+
}
177+
178+
@Override
179+
public void clearContent() {
180+
for(int i = 0; i < this.itemHandler.getSlots(); i++) {
181+
this.itemHandler.setStackInSlot(i, ItemStack.EMPTY);
182+
}
183+
}
184+
118185
public record Data(ParticleColliderBlockEntity blockEntity) implements ContainerData {
119186
@Override
120187
public int get(int index) {

src/main/java/top/ctnstudio/futurefood/common/block/tile/QedBlockEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
// TODO 添加配置功能
3333
// TODO 让外部无法提取能源
34-
public class QedBlockEntity extends BaseEnergyStorageBlockEntity<OutputEnergyMenu> implements IUnlimitedLinkModify {
34+
public class QedBlockEntity extends BaseEnergyStorageBlockEntity<OutputEnergyMenu>
35+
implements IUnlimitedLinkModify {
3536
public static final int DEFAULT_MAX_REMAINING_TIME = 5;
3637
protected final UnlimitedLinkStorage linkStorage; // 无限链接存储
3738

src/main/java/top/ctnstudio/futurefood/common/block/tile/QerBlockEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
// TODO 添加配置功能
2323
// TODO 让外部无法输入能源
24-
public class QerBlockEntity extends BaseEnergyStorageBlockEntity<InputEnergyMenu> implements IUnlimitedEntityReceive {
24+
public class QerBlockEntity extends BaseEnergyStorageBlockEntity<InputEnergyMenu>
25+
implements IUnlimitedEntityReceive {
2526

2627
public QerBlockEntity(BlockPos pos, BlockState blockState) {
2728
super(ModTileEntity.QER.get(), pos, blockState, new ModEnergyStorage(20480));

0 commit comments

Comments
 (0)