Search in sources :

Example 1 with TileEntityMachine

use of muramasa.antimatter.tile.TileEntityMachine in project GT-4-Reimagined by Trinsdar.

the class CoverConveyor method onUpdate.

@Override
public void onUpdate(CoverStack<?> instance, Direction side) {
    if (instance.getTile() == null || instance.getTile().getWorld().getGameTime() % (speeds.get(tier)) != 0)
        return;
    boolean isMachine = instance.getTile() instanceof TileEntityMachine;
    BlockState state = instance.getTile().getWorld().getBlockState(instance.getTile().getPos().offset(side));
    // Drop into world.
    if (state == Blocks.AIR.getDefaultState() && isMachine) {
        World world = instance.getTile().getWorld();
        BlockPos pos = instance.getTile().getPos();
        ItemStack stack = ((TileEntityMachine) instance.getTile()).itemHandler.map(ih -> Utils.extractAny(ih.getOutputHandler())).orElse(ItemStack.EMPTY);
        if (stack.isEmpty())
            return;
        world.addEntity(new ItemEntity(world, pos.getX() + side.getXOffset(), pos.getY() + side.getYOffset(), pos.getZ() + side.getZOffset(), stack));
    }
    if (!(state.hasTileEntity()))
        return;
    TileEntity adjTile = instance.getTile().getWorld().getTileEntity(instance.getTile().getPos().offset(side));
    if (adjTile == null) {
        return;
    }
    if (isMachine) {
        ((TileEntityMachine) instance.getTile()).itemHandler.ifPresent(ih -> adjTile.getCapability(ITEM_HANDLER_CAPABILITY).ifPresent(other -> Utils.transferItems(ih.getOutputHandler(), other, true)));
    } else {
        Utils.transferItemsOnCap(instance.getTile(), adjTile, true);
    }
}
Also used : ImmutableMap(com.google.common.collect.ImmutableMap) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) CoverTiered(muramasa.antimatter.cover.CoverTiered) Utils(muramasa.antimatter.util.Utils) Blocks(net.minecraft.block.Blocks) ItemStack(net.minecraft.item.ItemStack) Tier(muramasa.antimatter.machine.Tier) Map(java.util.Map) CoverStack(muramasa.antimatter.cover.CoverStack) TileEntity(net.minecraft.tileentity.TileEntity) ITEM_HANDLER_CAPABILITY(net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) Ref(trinsdar.gt4r.Ref) BlockState(net.minecraft.block.BlockState) ItemEntity(net.minecraft.entity.item.ItemEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) BlockState(net.minecraft.block.BlockState) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileEntityMachine

use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.

the class BlockMachine method createTileEntity.

@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
    TileEntityMachine machine = (TileEntityMachine) getType().getTileType().create();
    machine.ofState(state);
    return machine;
}
Also used : TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) Nullable(javax.annotation.Nullable)

Example 3 with TileEntityMachine

use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.

the class BlockMachine method getConfig.

@Override
public ModelConfig getConfig(BlockState state, IBlockReader world, BlockPos.Mutable mut, BlockPos pos) {
    Direction facing = state.get(BlockStateProperties.HORIZONTAL_FACING);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileEntityMachine) {
        MachineState machineState = ((TileEntityMachine) tile).getMachineState();
        if (((TileEntityMachine) tile).coverHandler.isPresent()) {
            CoverHandler<?> h = ((TileEntityMachine) tile).coverHandler.orElse(null);
            return config.set(new int[] { h.get(Utils.coverRotateFacing(UP, facing)).skipRender() ? getModelId(facing, UP, machineState) : 0, h.get(Utils.coverRotateFacing(DOWN, facing)).skipRender() ? getModelId(facing, DOWN, machineState) : 0, h.get(Utils.coverRotateFacing(NORTH, facing)).skipRender() ? getModelId(facing, NORTH, machineState) : 0, h.get(Utils.coverRotateFacing(SOUTH, facing)).skipRender() ? getModelId(facing, SOUTH, machineState) : 0, h.get(Utils.coverRotateFacing(WEST, facing)).skipRender() ? getModelId(facing, WEST, machineState) : 0, h.get(Utils.coverRotateFacing(EAST, facing)).skipRender() ? getModelId(facing, EAST, machineState) : 0 });
        } else {
            return config.set(new int[] { getModelId(facing, UP, machineState), getModelId(facing, DOWN, machineState), getModelId(facing, NORTH, machineState), getModelId(facing, SOUTH, machineState), getModelId(facing, WEST, machineState), getModelId(facing, EAST, machineState) });
        }
    }
    return config.set(new int[] { 0 });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) Direction(net.minecraft.util.Direction)

Example 4 with TileEntityMachine

use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.

the class CoverOutput method onMachineEvent.

@Override
public void onMachineEvent(CoverInstance instance, TileEntityMachine tile, IMachineEvent event) {
    // TODO: Refactor? <- YES!
    if (event == MachineEvent.ITEMS_OUTPUTTED && instance.getNbt().getBoolean(KEY_OUTPUT)) {
        Direction outputDir = tile.getOutputFacing();
        TileEntity adjTile = Utils.getTile(tile.getWorld(), tile.getPos().offset(outputDir));
        if (adjTile == null)
            return;
        adjTile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, outputDir.getOpposite()).ifPresent(adjHandler -> {
            tile.itemHandler.ifPresent(h -> Utils.transferItems(h.getOutputHandler(), adjHandler));
        });
    } else if (event == MachineEvent.FLUIDS_OUTPUTTED) {
        Direction outputDir = tile.getOutputFacing();
        TileEntity adjTile = Utils.getTile(tile.getWorld(), tile.getPos().offset(outputDir));
        if (adjTile == null)
            return;
        adjTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, outputDir.getOpposite()).ifPresent(adjHandler -> {
            tile.fluidHandler.ifPresent(h -> Utils.transferFluids(h.getOutputTanks(), adjHandler));
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AntimatterAPI(muramasa.antimatter.AntimatterAPI) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) MachineEvent(muramasa.antimatter.machine.event.MachineEvent) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntity(net.minecraft.tileentity.TileEntity) Direction(net.minecraft.util.Direction) IMachineEvent(muramasa.antimatter.machine.event.IMachineEvent) Utils(muramasa.antimatter.util.Utils) Direction(net.minecraft.util.Direction)

Example 5 with TileEntityMachine

use of muramasa.antimatter.tile.TileEntityMachine in project AntimatterAPI by GregTech-Intergalactical.

the class BlockMachine method onBlockActivated.

@Nonnull
@Override
public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
    if (!world.isRemote) {
        TileEntityMachine tile = (TileEntityMachine) world.getTileEntity(pos);
        if (tile != null) {
            AntimatterCaps.getCustomEnergyHandler(tile).ifPresent(e -> System.out.println(e.getEnergy()));
            ItemStack stack = player.getHeldItem(hand);
            AntimatterToolType type = Utils.getToolType(player);
            if (hand == Hand.MAIN_HAND) {
                if (player.getHeldItem(hand).getItem() instanceof ItemCover) {
                    boolean ok = tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY, hit.getFace()).map(i -> i.placeCover(player, hit.getFace(), stack, ((ItemCover) stack.getItem()).getCover())).orElse(false);
                    if (ok) {
                        return ActionResultType.SUCCESS;
                    }
                }
                // Handle tool types.
                if (type == WRENCH || type == ELECTRIC_WRENCH) {
                    boolean ok = player.isCrouching() ? tile.setFacing(Utils.getInteractSide(hit)) : tile.setOutputFacing(Utils.getInteractSide(hit));
                    return ok ? ActionResultType.SUCCESS : ActionResultType.PASS;
                } else if (type == HAMMER) {
                    tile.toggleMachine();
                    // TODO: Replace by new TranslationTextComponent()
                    player.sendMessage(new StringTextComponent("Machine was " + (tile.getMachineState() == MachineState.DISABLED ? "disabled" : "enabled")));
                    return ActionResultType.SUCCESS;
                } else if (type == CROWBAR) {
                    return tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.removeCover(player, hit.getFace())).orElse(false) ? ActionResultType.SUCCESS : ActionResultType.PASS;
                } else if (type == SCREWDRIVER || type == ELECTRIC_SCREWDRIVER) {
                    CoverInstance<?> instance = tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.get(hit.getFace())).orElse(COVER_EMPTY);
                    return !instance.isEmpty() && instance.getCover().hasGui() && instance.openGui(player, hit.getFace()) ? ActionResultType.SUCCESS : ActionResultType.PASS;
                }
                // Has gui?
                if (getType().has(MachineFlag.GUI)) {
                    NetworkHooks.openGui((ServerPlayerEntity) player, tile, tile.getPos());
                    return ActionResultType.SUCCESS;
                }
                // Otherwise, interact with fluids
                if (tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, hit.getFace()).map(fh -> FluidUtil.tryEmptyContainer(stack, fh, 1000, player, true).success).orElse(false)) {
                    return ActionResultType.SUCCESS;
                }
                return tile.getCapability(AntimatterCaps.COVERABLE_HANDLER_CAPABILITY).map(h -> h.onInteract(player, hand, hit.getFace(), Utils.getToolType(player))).orElse(false) ? ActionResultType.SUCCESS : ActionResultType.PASS;
            }
        }
    }
    return ActionResultType.PASS;
}
Also used : ItemModelBuilder(net.minecraftforge.client.model.generators.ItemModelBuilder) Arrays(java.util.Arrays) Direction(net.minecraft.util.Direction) CoverHandler(muramasa.antimatter.capability.CoverHandler) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IAntimatterObject(muramasa.antimatter.registration.IAntimatterObject) IBlockReader(net.minecraft.world.IBlockReader) Block(net.minecraft.block.Block) StringTextComponent(net.minecraft.util.text.StringTextComponent) Ref(muramasa.antimatter.Ref) ModelConfig(muramasa.antimatter.dynamic.ModelConfig) BlockState(net.minecraft.block.BlockState) ItemCover(muramasa.antimatter.item.ItemCover) Texture(muramasa.antimatter.texture.Texture) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AntimatterBlockStateProvider(muramasa.antimatter.datagen.providers.AntimatterBlockStateProvider) LivingEntity(net.minecraft.entity.LivingEntity) AntimatterItemModelProvider(muramasa.antimatter.datagen.providers.AntimatterItemModelProvider) BlockItemUseContext(net.minecraft.item.BlockItemUseContext) ImmutableMap.of(com.google.common.collect.ImmutableMap.of) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) COVER_EMPTY(muramasa.antimatter.Data.COVER_EMPTY) List(java.util.List) AntimatterBlockModelBuilder(muramasa.antimatter.datagen.builder.AntimatterBlockModelBuilder) ToolType(net.minecraftforge.common.ToolType) ItemGroup(net.minecraft.item.ItemGroup) AntimatterToolType(muramasa.antimatter.tool.AntimatterToolType) ActionResultType(net.minecraft.util.ActionResultType) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FluidUtil(net.minecraftforge.fluids.FluidUtil) IColorHandler(muramasa.antimatter.registration.IColorHandler) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) CoverInstance(muramasa.antimatter.cover.CoverInstance) IItemBlockProvider(muramasa.antimatter.registration.IItemBlockProvider) Utils(muramasa.antimatter.util.Utils) ITextComponent(net.minecraft.util.text.ITextComponent) ItemStack(net.minecraft.item.ItemStack) StateContainer(net.minecraft.state.StateContainer) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) Data(muramasa.antimatter.Data) Hand(net.minecraft.util.Hand) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) SoundType(net.minecraft.block.SoundType) BASIC(muramasa.antimatter.machine.MachineFlag.BASIC) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) World(net.minecraft.world.World) TextFormatting(net.minecraft.util.text.TextFormatting) BlockPos(net.minecraft.util.math.BlockPos) AntimatterCaps(muramasa.antimatter.capability.AntimatterCaps) AntimatterModelManager(muramasa.antimatter.client.AntimatterModelManager) BlockDynamic(muramasa.antimatter.dynamic.BlockDynamic) IItemProvider(net.minecraft.util.IItemProvider) Material(net.minecraft.block.material.Material) Machine(muramasa.antimatter.machine.types.Machine) TileEntity(net.minecraft.tileentity.TileEntity) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) ItemCover(muramasa.antimatter.item.ItemCover) CoverInstance(muramasa.antimatter.cover.CoverInstance) TileEntityMachine(muramasa.antimatter.tile.TileEntityMachine) AntimatterToolType(muramasa.antimatter.tool.AntimatterToolType) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

TileEntityMachine (muramasa.antimatter.tile.TileEntityMachine)5 TileEntity (net.minecraft.tileentity.TileEntity)4 Direction (net.minecraft.util.Direction)4 Utils (muramasa.antimatter.util.Utils)3 Nullable (javax.annotation.Nullable)2 BlockState (net.minecraft.block.BlockState)2 CapabilityFluidHandler (net.minecraftforge.fluids.capability.CapabilityFluidHandler)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.of (com.google.common.collect.ImmutableMap.of)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 AntimatterAPI (muramasa.antimatter.AntimatterAPI)1 Data (muramasa.antimatter.Data)1 COVER_EMPTY (muramasa.antimatter.Data.COVER_EMPTY)1 Ref (muramasa.antimatter.Ref)1 AntimatterCaps (muramasa.antimatter.capability.AntimatterCaps)1 CoverHandler (muramasa.antimatter.capability.CoverHandler)1 AntimatterModelManager (muramasa.antimatter.client.AntimatterModelManager)1