use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.
the class MultiblockControllerBase method checkStructurePattern.
protected void checkStructurePattern() {
EnumFacing facing = getFrontFacing().getOpposite();
PatternMatchContext context = structurePattern.checkPatternAt(getWorld(), getPos(), facing);
if (context != null && !structureFormed) {
Set<IMultiblockPart> rawPartsSet = context.getOrCreate("MultiblockParts", HashSet::new);
ArrayList<IMultiblockPart> parts = new ArrayList<>(rawPartsSet);
parts.sort(Comparator.comparing(it -> ((MetaTileEntity) it).getPos().hashCode()));
for (IMultiblockPart part : parts) {
if (part.isAttachedToMultiBlock()) {
// stop here without attempting to register abilities
return;
}
}
Map<MultiblockAbility<Object>, List<Object>> abilities = new HashMap<>();
for (IMultiblockPart multiblockPart : parts) {
if (multiblockPart instanceof IMultiblockAbilityPart) {
IMultiblockAbilityPart<Object> abilityPart = (IMultiblockAbilityPart<Object>) multiblockPart;
List<Object> abilityInstancesList = abilities.computeIfAbsent(abilityPart.getAbility(), k -> new ArrayList<>());
abilityPart.registerAbilities(abilityInstancesList);
}
}
if (checkStructureComponents(parts, abilities)) {
parts.forEach(part -> part.addToMultiBlock(this));
this.multiblockParts.addAll(parts);
this.multiblockAbilities.putAll(abilities);
this.structureFormed = true;
writeCustomData(400, buf -> buf.writeBoolean(true));
formStructure(context);
}
} else if (context == null && structureFormed) {
invalidateStructure();
}
}
use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.
the class BlockMachine method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
MetaTileEntityHolder holder = (MetaTileEntityHolder) worldIn.getTileEntity(pos);
MetaTileEntity sampleMetaTileEntity = GregTechAPI.META_TILE_ENTITY_REGISTRY.getObjectById(stack.getItemDamage());
if (holder != null && sampleMetaTileEntity != null) {
MetaTileEntity metaTileEntity = holder.setMetaTileEntity(sampleMetaTileEntity);
if (stack.hasTagCompound()) {
metaTileEntity.initFromItemStackData(stack.getTagCompound());
}
EnumFacing placeFacing = placer.getHorizontalFacing().getOpposite();
if (metaTileEntity.isValidFrontFacing(placeFacing)) {
metaTileEntity.setFrontFacing(placeFacing);
}
}
}
use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.
the class BlockMachine method getCollisionBox.
private List<IndexedCuboid6> getCollisionBox(IBlockAccess blockAccess, BlockPos pos) {
MetaTileEntity metaTileEntity = getMetaTileEntity(blockAccess, pos);
if (metaTileEntity == null)
return EMPTY_COLLISION_BOX;
ArrayList<IndexedCuboid6> collisionList = new ArrayList<>();
metaTileEntity.addCollisionBoundingBox(collisionList);
metaTileEntity.addCoverCollisionBoundingBox(collisionList);
return collisionList;
}
use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.
the class BlockMachine method breakBlock.
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
if (metaTileEntity != null) {
if (!metaTileEntity.keepsInventory()) {
NonNullList<ItemStack> inventoryContents = NonNullList.create();
metaTileEntity.clearMachineInventory(inventoryContents);
for (ItemStack itemStack : inventoryContents) {
Block.spawnAsEntity(worldIn, pos, itemStack);
}
}
metaTileEntity.dropAllCovers();
metaTileEntity.onRemoval();
tileEntities.set(metaTileEntity);
}
super.breakBlock(worldIn, pos, state);
}
use of gregtech.api.metatileentity.MetaTileEntity in project GregTech by GregTechCE.
the class BlockMachine method rotateBlock.
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
if (metaTileEntity == null || !metaTileEntity.isValidFrontFacing(axis) || metaTileEntity.getFrontFacing() == axis || !metaTileEntity.hasFrontFacing())
return false;
metaTileEntity.setFrontFacing(axis);
return true;
}
Aggregations