-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIXME: screen won't fucking open for some reason
- Loading branch information
Showing
22 changed files
with
1,158 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/gripe/_90/appliede/iface/EMCInterfaceBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package gripe._90.appliede.iface; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
|
||
import appeng.block.AEBaseEntityBlock; | ||
import appeng.menu.locator.MenuLocators; | ||
import appeng.util.InteractionUtil; | ||
|
||
public class EMCInterfaceBlock extends AEBaseEntityBlock<EMCInterfaceBlockEntity> { | ||
public EMCInterfaceBlock() { | ||
super(metalProps()); | ||
} | ||
|
||
@Override | ||
public InteractionResult onActivated( | ||
Level level, | ||
BlockPos pos, | ||
Player player, | ||
InteractionHand hand, | ||
@Nullable ItemStack heldItem, | ||
BlockHitResult hit) { | ||
if (InteractionUtil.isInAlternateUseMode(player)) { | ||
return InteractionResult.PASS; | ||
} | ||
|
||
var be = this.getBlockEntity(level, pos); | ||
|
||
if (be != null) { | ||
if (!level.isClientSide()) { | ||
be.openMenu(player, MenuLocators.forBlockEntity(be)); | ||
} | ||
|
||
return InteractionResult.sidedSuccess(level.isClientSide()); | ||
} | ||
|
||
return InteractionResult.PASS; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
src/main/java/gripe/_90/appliede/iface/EMCInterfaceBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package gripe._90.appliede.iface; | ||
|
||
import java.util.List; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
|
||
import appeng.api.networking.GridHelper; | ||
import appeng.api.networking.IGridNode; | ||
import appeng.api.networking.IGridNodeListener; | ||
import appeng.api.networking.IManagedGridNode; | ||
import appeng.blockentity.grid.AENetworkBlockEntity; | ||
import appeng.me.helpers.BlockEntityNodeListener; | ||
|
||
import gripe._90.appliede.AppliedE; | ||
|
||
public class EMCInterfaceBlockEntity extends AENetworkBlockEntity implements EMCInterfaceLogicHost { | ||
private static final IGridNodeListener<EMCInterfaceBlockEntity> NODE_LISTENER = new BlockEntityNodeListener<>() { | ||
@Override | ||
public void onGridChanged(EMCInterfaceBlockEntity nodeOwner, IGridNode node) { | ||
nodeOwner.logic.notifyNeighbours(); | ||
} | ||
}; | ||
|
||
private final EMCInterfaceLogic logic = createLogic(); | ||
|
||
public EMCInterfaceBlockEntity(BlockPos pos, BlockState blockState) { | ||
super(AppliedE.EMC_INTERFACE_BE.get(), pos, blockState); | ||
} | ||
|
||
protected EMCInterfaceLogic createLogic() { | ||
return new EMCInterfaceLogic(getMainNode(), this); | ||
} | ||
|
||
@Override | ||
protected IManagedGridNode createMainNode() { | ||
return GridHelper.createManagedNode(this, NODE_LISTENER); | ||
} | ||
|
||
@Override | ||
public EMCInterfaceLogic getInterfaceLogic() { | ||
return logic; | ||
} | ||
|
||
@Override | ||
public void onMainNodeStateChanged(IGridNodeListener.State reason) { | ||
if (getMainNode().hasGridBooted()) { | ||
logic.notifyNeighbours(); | ||
} | ||
} | ||
|
||
@Override | ||
public void saveAdditional(CompoundTag data) { | ||
super.saveAdditional(data); | ||
logic.writeToNBT(data); | ||
} | ||
|
||
@Override | ||
public void loadTag(CompoundTag data) { | ||
super.loadTag(data); | ||
logic.readFromNBT(data); | ||
} | ||
|
||
@Override | ||
public void addAdditionalDrops(Level level, BlockPos pos, List<ItemStack> drops) { | ||
super.addAdditionalDrops(level, pos, drops); | ||
logic.addDrops(drops); | ||
} | ||
|
||
@Override | ||
public void clearContent() { | ||
super.clearContent(); | ||
getStorage().clear(); | ||
} | ||
|
||
@Override | ||
public ItemStack getMainMenuIcon() { | ||
return AppliedE.EMC_INTERFACE.get().asItem().getDefaultInstance(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { | ||
var capability = logic.getCapability(cap); | ||
return capability.isPresent() ? capability : super.getCapability(cap, side); | ||
} | ||
|
||
@Override | ||
public void invalidateCaps() { | ||
super.invalidateCaps(); | ||
logic.invalidateCaps(); | ||
} | ||
} |
Oops, something went wrong.