Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,11 @@ public BlockState rotate(BlockState pState, Rotation pRotation) {

@Override
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
BlockEntity tileEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
var drops = super.getDrops(state, builder);
if (tileEntity instanceof MetaMachine machine) {
if (machine instanceof IMachineModifyDrops machineModifyDrops) {
machineModifyDrops.onDrops(drops);
}

BlockEntity be = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (be instanceof MetaMachine machine) {
machine.modifyDrops(drops);
if (machine instanceof IDropSaveMachine dropSaveMachine && dropSaveMachine.saveBreak()) {
for (ItemStack drop : drops) {
if (drop.getItem() instanceof MetaMachineItem item && item.getBlock() == this) {
Expand All @@ -248,7 +247,7 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState
if (!pState.is(pNewState.getBlock())) { // new block
MetaMachine machine = MetaMachine.getMachine(pLevel, pPos);
if (machine != null) {
machine.onRemoved();
machine.onMachineDestroyed();
}

pLevel.updateNeighbourForOutputSignal(pPos, this);
Expand Down Expand Up @@ -278,18 +277,8 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
machine.setOwnerUUID(sPlayer.getUUID());
}

Set<GTToolType> types = ToolHelper.getToolTypes(itemStack);
if (!types.isEmpty() && ToolHelper.canUse(itemStack) || types.isEmpty() && player.isShiftKeyDown()) {
var result = machine.onToolClick(types, itemStack, new UseOnContext(player, hand, hit));
if (result.getSecond() == InteractionResult.CONSUME && player instanceof ServerPlayer serverPlayer) {
ToolHelper.playToolSound(result.getFirst(), serverPlayer);

if (!serverPlayer.isCreative()) {
ToolHelper.damageItem(itemStack, serverPlayer, 1);
}
}
if (result.getSecond() != InteractionResult.PASS) return result.getSecond();
}
InteractionResult machineInteractResult = machine.onUse(state, world, pos, player, hand, hit);
if (machineInteractResult != InteractionResult.PASS) return machineInteractResult;

if (itemStack.is(GTItems.PORTABLE_SCANNER.get())) {
return itemStack.getItem().use(world, player, hand).getResult();
Expand All @@ -299,17 +288,6 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
shouldOpenUi = gtToolItem.definition$shouldOpenUIAfterUse(new UseOnContext(player, hand, hit));
}

for (var trait : machine.getTraitHolder().getAllTraits()) {
if (trait instanceof IInteractionTrait interactionTrait) {
InteractionResult result = interactionTrait.onUse(state, world, pos, player, hand, hit);
if (result != InteractionResult.PASS) return result;
}
}

if (machine instanceof IInteractedMachine interactedMachine) {
var result = interactedMachine.onUse(state, world, pos, player, hand, hit);
if (result != InteractionResult.PASS) return result;
}
if (shouldOpenUi && machine instanceof IUIMachine uiMachine &&
MachineOwner.canOpenOwnerMachine(player, machine)) {
return uiMachine.tryToOpenUI(player, hand, hit);
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/com/gregtechceu/gtceu/api/capability/IMiner.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
package com.gregtechceu.gtceu.api.capability;

import com.gregtechceu.gtceu.api.machine.feature.IMachineLife;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.common.machine.trait.miner.MinerLogic;

public interface IMiner extends IRecipeLogicMachine, IMachineLife {

@Override
MinerLogic getRecipeLogic();

@Override
default void onMachineRemoved() {
getRecipeLogic().onRemove();
}
public interface IMiner extends IRecipeLogicMachine {

boolean drainInput(boolean simulate);

Expand Down
92 changes: 61 additions & 31 deletions src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.gregtechceu.gtceu.api.gui.fancy.IFancyTooltip;
import com.gregtechceu.gtceu.api.item.tool.GTToolType;
import com.gregtechceu.gtceu.api.item.tool.IToolGridHighlight;
import com.gregtechceu.gtceu.api.item.tool.ToolHelper;
import com.gregtechceu.gtceu.api.machine.feature.*;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
Expand Down Expand Up @@ -102,8 +103,6 @@

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class MetaMachine extends ManagedSyncBlockEntity implements IGregtechBlockEntity, IToolable, IToolGridHighlight,
IFancyTooltip, IPaintable, IMachineFeature, ICopyable {

Expand Down Expand Up @@ -157,26 +156,6 @@ public MetaMachine(BlockEntityCreationInfo info) {
// ***** Machine Lifecycle ******//
//////////////////////////////////////

public void onMachinePlaced(@Nullable LivingEntity player, ItemStack stack) {
if (player instanceof ServerPlayer sPlayer) {
ownerUUID = sPlayer.getUUID();
}

if (this instanceof IDropSaveMachine dropSaveMachine) {
CompoundTag tag = stack.getTag();
if (tag != null) {
dropSaveMachine.loadFromItem(tag);
}
}
}

public void onRemoved() {
for (Direction direction : GTUtil.DIRECTIONS) {
getCoverContainer().removeCover(direction, null);
}
if (this instanceof IMachineLife l) l.onMachineRemoved();
}

@Override
public void load(CompoundTag tag) {
TagCompatibilityFixer.fixMachineAutoOutputTag(tag);
Expand All @@ -196,14 +175,6 @@ public void onLoad() {
}
}

public void setRenderState(MachineRenderState renderState) {
this.renderState = renderState;
if (level != null && !level.isClientSide) {
syncDataHolder.markClientSyncFieldDirty("renderState");
}
scheduleRenderUpdate();
}

@Override
public final void setRemoved() {
super.setRemoved();
Expand All @@ -220,6 +191,27 @@ public void onUnload() {
serverTicks.clear();
}

public void onMachinePlaced(@Nullable LivingEntity player, ItemStack stack) {
if (player instanceof ServerPlayer sPlayer) {
ownerUUID = sPlayer.getUUID();
}

if (this instanceof IDropSaveMachine dropSaveMachine) {
CompoundTag tag = stack.getTag();
if (tag != null) {
dropSaveMachine.loadFromItem(tag);
}
}
}

public void onMachineDestroyed() {
for (Direction direction : GTUtil.DIRECTIONS) {
getCoverContainer().removeCover(direction, null);
}
}

public void modifyDrops(List<ItemStack> drops) {}

//////////////////////////////////////
// ***** Tickable Manager ****//
//////////////////////////////////////
Expand Down Expand Up @@ -288,7 +280,7 @@ private void executeTick() {
//////////////////////////////////////

/**
* Called when a player clicks this meta tile entity with a tool
* Called when a player clicks this machine with a tool
*
* @return SUCCESS / CONSUME (will damage tool) / FAIL if something happened, so tools will get damaged and
* animations will be played
Expand Down Expand Up @@ -402,6 +394,36 @@ protected InteractionResult onScrewdriverClick(Player playerIn, InteractionHand
return InteractionResult.PASS;
}

/**
* Called when a machine is clicked.
*/
public InteractionResult onUse(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand,
BlockHitResult hit) {
ItemStack itemStack = player.getItemInHand(hand);

Set<GTToolType> types = ToolHelper.getToolTypes(itemStack);
if (!types.isEmpty() && ToolHelper.canUse(itemStack) || types.isEmpty() && player.isShiftKeyDown()) {
var result = onToolClick(types, itemStack, new UseOnContext(player, hand, hit));
if (result.getSecond() == InteractionResult.CONSUME && player instanceof ServerPlayer serverPlayer) {
ToolHelper.playToolSound(result.getFirst(), serverPlayer);

if (!serverPlayer.isCreative()) {
ToolHelper.damageItem(itemStack, serverPlayer, 1);
}
}
if (result.getSecond() != InteractionResult.PASS) return result.getSecond();
}

for (var trait : getTraitHolder().getAllTraits()) {
if (trait instanceof IInteractionTrait interactionTrait) {
InteractionResult result = interactionTrait.onUse(state, world, pos, player, hand, hit);
if (result != InteractionResult.PASS) return result;
}
}

return InteractionResult.PASS;
}

//////////////////////////////////////
// ********** MISC ***********//
//////////////////////////////////////
Expand Down Expand Up @@ -440,6 +462,14 @@ public boolean triggerEvent(int id, int para) {
return false;
}

public void setRenderState(MachineRenderState renderState) {
this.renderState = renderState;
if (level != null && !level.isClientSide) {
syncDataHolder.markClientSyncFieldDirty("renderState");
}
scheduleRenderUpdate();
}

public void setPaintingColor(int color) {
if (color == this.paintingColor) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class SimpleGeneratorMachine extends WorkableTieredMachine
implements IFancyUIMachine, IEnvironmentalHazardEmitter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
/**
* All simple single machines are implemented here.
*/
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class SimpleTieredMachine extends WorkableTieredMachine
implements IFancyUIMachine, IHasCircuitSlot {

Expand Down Expand Up @@ -133,8 +131,8 @@ protected void chargeBattery() {
// ********** MISC ***********//
//////////////////////////////////////
@Override
public void onMachineRemoved() {
super.onMachineRemoved();
public void onMachineDestroyed() {
super.onMachineDestroyed();
clearInventory(chargerInventory);
if (!ConfigHolder.INSTANCE.machines.ghostCircuit) {
clearInventory(circuitInventory.storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@

import javax.annotation.ParametersAreNonnullByDefault;

@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public abstract class WorkableTieredMachine extends TieredEnergyMachine implements IRecipeLogicMachine,
IMachineLife, IMufflableMachine, IOverclockMachine {
IMufflableMachine, IOverclockMachine {

@Getter
@SaveField
Expand Down Expand Up @@ -144,7 +142,8 @@ public void onUnload() {
//////////////////////////////////////

@Override
public void onMachineRemoved() {
public void onMachineDestroyed() {
super.onMachineDestroyed();
clearInventory(importItems.storage);
clearInventory(exportItems.storage);
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading