support create:alloyed and optimize

This commit is contained in:
khj xiaogu 2022-01-20 16:36:29 +08:00
parent 4868d2133c
commit fc012134a8
No known key found for this signature in database
GPG key ID: DEA172814EAFF426
16 changed files with 55 additions and 137 deletions

View file

@ -113,6 +113,7 @@ dependencies {
implementation fg.deobf("curse.maven:create-328085:3499718")
implementation fg.deobf("curse.maven:flywheel-486392:3459739")
implementation fg.deobf("curse.maven:immersive-engineering-231951:3377691")
implementation fg.deobf("curse.maven:create-alloyed-564792:3602444")
compileOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.4.88:api")
runtimeOnly fg.deobf("mezz.jei:jei-1.16.5:7.6.4.88")

View file

@ -21,7 +21,7 @@ package com.teammoeg.steampowered.content.alternator;
import java.util.List;
import java.util.Random;
import com.simibubi.create.content.contraptions.base.DirectionalKineticBlock;
import com.simibubi.create.content.contraptions.base.HorizontalKineticBlock;
import com.simibubi.create.content.contraptions.base.IRotate;
import com.simibubi.create.foundation.block.ITE;
import com.simibubi.create.foundation.item.ItemDescription.Palette;
@ -38,6 +38,7 @@ import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.Property;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
@ -58,10 +59,10 @@ import net.minecraft.world.server.ServerWorld;
* @author MRH0
* @author yuesha-yc
*/
public class DynamoBlock extends DirectionalKineticBlock implements ITE<DynamoTileEntity>, IRotate {
public class DynamoBlock extends HorizontalKineticBlock implements ITE<DynamoTileEntity>, IRotate {
public static final BooleanProperty REDSTONE_LOCKED = BooleanProperty.create("redstone_locked");
public static final Property<Direction> FACING=HORIZONTAL_FACING;
public static final VoxelShaper DYNAMO_SHAPE = SPShapes
.shape(2, 0, 1, 14, 4, 16)
.add(3, 3, 2, 13, 15, 13)
@ -75,7 +76,7 @@ public class DynamoBlock extends DirectionalKineticBlock implements ITE<DynamoTi
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
Direction preferred = getPreferredFacing(context);
Direction preferred = getPreferredHorizontalFacing(context);
if ((context.getPlayer() != null && context.getPlayer().isShiftKeyDown()) || preferred == null) {
return super.getStateForPlacement(context).setValue(REDSTONE_LOCKED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
}
@ -152,13 +153,6 @@ public class DynamoBlock extends DirectionalKineticBlock implements ITE<DynamoTi
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean flag) {
if (!world.isClientSide) {
TileEntity tileentity = state.hasTileEntity() ? world.getBlockEntity(pos) : null;
if (tileentity != null) {
if (tileentity instanceof DynamoTileEntity) {
((DynamoTileEntity) tileentity).updateCache();
}
}
boolean isLocked = state.getValue(REDSTONE_LOCKED);
if (isLocked != world.hasNeighborSignal(pos)) {
if (isLocked) {

View file

@ -4,17 +4,16 @@ import com.jozufozu.flywheel.backend.material.MaterialManager;
import com.simibubi.create.content.contraptions.base.HalfShaftInstance;
import com.simibubi.create.content.contraptions.base.KineticTileEntity;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction;
public class RevertHalfShaftInstance extends HalfShaftInstance {
public class DynamoShaftInstance extends HalfShaftInstance {
public RevertHalfShaftInstance(MaterialManager<?> modelManager, KineticTileEntity tile) {
public DynamoShaftInstance(MaterialManager<?> modelManager, KineticTileEntity tile) {
super(modelManager, tile);
}
@Override
protected Direction getShaftDirection() {
return blockState.getValue(BlockStateProperties.FACING).getOpposite();
return blockState.getValue(DynamoBlock.FACING).getOpposite();
}
}

View file

@ -93,19 +93,10 @@ public class DynamoTileEntity extends KineticTileEntity {
@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
if (cap == CapabilityEnergy.ENERGY && (isEnergyInput(side) || isEnergyOutput(side)))// && !level.isClientSide
if (cap == CapabilityEnergy.ENERGY && side==getBlockState().getValue(DynamoBlock.FACING))// && !level.isClientSide
return lazyEnergy.cast();
return super.getCapability(cap, side);
}
public boolean isEnergyInput(Direction side) {
return false;
}
public boolean isEnergyOutput(Direction side) {
return side != getBlockState().getValue(DynamoBlock.FACING).getOpposite();
}
@Override
public void fromTag(BlockState state, CompoundNBT compound, boolean clientPacket) {
super.fromTag(state, compound, clientPacket);
@ -120,32 +111,21 @@ public class DynamoTileEntity extends KineticTileEntity {
compound.putBoolean("redstonelocked", redstoneLocked);
}
private boolean firstTickState = true;
@Override
public void tick() {
super.tick();
if (level != null && level.isClientSide())
return;
if (this.getBlockState().getValue(DynamoBlock.REDSTONE_LOCKED))
return;
if (firstTickState)
firstTick();
firstTickState = false;
if (Math.abs(getSpeed()) > 0 && isSpeedRequirementFulfilled())
energy.internalProduceEnergy(getEnergyProductionRate((int) getSpeed()));
for (Direction d : Direction.values()) {
if (!isEnergyOutput(d))
continue;
IEnergyStorage ies = getCachedEnergy(d);
if (ies == null)
continue;
int ext = energy.extractEnergy(ies.receiveEnergy(MAX_FE_OUT, true), false);
ies.receiveEnergy(ext, false);
Direction side=this.getBlockState().getValue(DynamoBlock.FACING);
TileEntity te = level.getBlockEntity(worldPosition.relative(side));
if (te != null) {
te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite())
.ifPresent(ies->ies.receiveEnergy(energy.extractEnergy(ies.receiveEnergy(MAX_FE_OUT, true), false), false));
}
}
@ -159,73 +139,6 @@ public class DynamoTileEntity extends KineticTileEntity {
super.setRemoved();
lazyEnergy.invalidate();
}
public void firstTick() {
updateCache();
}
public void updateCache() {
if (level.isClientSide())
return;
for (Direction side : Direction.values()) {
TileEntity te = level.getBlockEntity(worldPosition.relative(side));
if (te == null) {
setCache(side, LazyOptional.empty());
continue;
}
LazyOptional<IEnergyStorage> le = te.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
setCache(side, le);
}
}
private LazyOptional<IEnergyStorage> escacheUp = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheDown = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheNorth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheEast = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheSouth = LazyOptional.empty();
private LazyOptional<IEnergyStorage> escacheWest = LazyOptional.empty();
public void setCache(Direction side, LazyOptional<IEnergyStorage> storage) {
switch (side) {
case DOWN:
escacheDown = storage;
break;
case EAST:
escacheEast = storage;
break;
case NORTH:
escacheNorth = storage;
break;
case SOUTH:
escacheSouth = storage;
break;
case UP:
escacheUp = storage;
break;
case WEST:
escacheWest = storage;
break;
}
}
public IEnergyStorage getCachedEnergy(Direction side) {
switch (side) {
case DOWN:
return escacheDown.orElse(null);
case EAST:
return escacheEast.orElse(null);
case NORTH:
return escacheNorth.orElse(null);
case SOUTH:
return escacheSouth.orElse(null);
case UP:
return escacheUp.orElse(null);
case WEST:
return escacheWest.orElse(null);
}
return null;
}
@Override
public World getWorld() {
return getLevel();

View file

@ -25,8 +25,6 @@ import com.simibubi.create.foundation.item.ItemDescription.Palette;
import com.simibubi.create.foundation.item.TooltipHelper;
import com.simibubi.create.foundation.utility.Lang;
import com.teammoeg.steampowered.client.ClientUtils;
import com.teammoeg.steampowered.content.alternator.DynamoTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.client.gui.screen.Screen;
@ -36,13 +34,11 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Direction;
@ -63,7 +59,7 @@ import net.minecraftforge.items.IItemHandler;
public abstract class BurnerBlock extends Block {
public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final DirectionProperty FACING = BlockStateProperties.FACING;
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public static final BooleanProperty REDSTONE_LOCKED = BooleanProperty.create("redstone_locked");
public BurnerBlock(Properties props) {
super(props.lightLevel(s->s.getValue(LIT)?10:0));
@ -161,13 +157,6 @@ public abstract class BurnerBlock extends Block {
@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean flag) {
if (!world.isClientSide) {
TileEntity tileentity = state.hasTileEntity() ? world.getBlockEntity(pos) : null;
if (tileentity != null) {
if (tileentity instanceof DynamoTileEntity) {
((DynamoTileEntity) tileentity).updateCache();
}
}
boolean isLocked = state.getValue(REDSTONE_LOCKED);
if (isLocked != world.hasNeighborSignal(pos)) {
if (isLocked) {

View file

@ -100,7 +100,7 @@ public class SPTiles {
public static final TileEntityEntry<DynamoTileEntity> DYNAMO = REGISTRATE
.tileEntity("alternator", DynamoTileEntity::new)
.instance(() -> com.teammoeg.steampowered.content.alternator.RevertHalfShaftInstance::new)
.instance(() -> com.teammoeg.steampowered.content.alternator.DynamoShaftInstance::new)
.validBlocks(SPBlocks.DYNAMO)
.register();

View file

@ -38,3 +38,10 @@ Expanding Create mod to the Steam Age
versionRange="[1.16-0.2.3,1.16-0.3)"
ordering="AFTER"
side="CLIENT"
[[dependencies.steampowered]]
modId="alloyed"
mandatory=false
versionRange="[1.16.5,)"
ordering="AFTER"
side="BOTH"

View file

@ -2,9 +2,9 @@
"type": "create:mechanical_crafting",
"pattern": [
" IRI ",
"ILCLI",
"RCSCR",
"ILCLI",
"ILILI",
"RLSLR",
"ILILI",
" IRI "
],
"key": {
@ -12,16 +12,13 @@
"tag": "forge:ingots/iron"
},
"R": {
"item": "minecraft:redstone_block"
"item": "minecraft:redstone"
},
"S": {
"item": "create:shaft"
},
"C": {
"item": "steampowered:cast_iron_cogwheel"
},
"L": {
"item": "steampowered:cast_iron_large_cogwheel"
"tag": "forge:plates/copper"
}
},
"result": {

View file

@ -7,7 +7,7 @@
],
"key": {
"S": {
"tag": "forge:plates/brass"
"tag": "steampowered:bronzeplate"
},
"C": {
"item": "create:fluid_pipe"

View file

@ -7,7 +7,7 @@
],
"key": {
"S": {
"tag": "forge:plates/brass"
"tag": "steampowered:bronzeplate"
},
"C": {
"item": "minecraft:bricks"

View file

@ -7,7 +7,7 @@
],
"key": {
"S": {
"tag": "forge:ingots/brass"
"tag": "steampowered:bronze"
},
"C": {
"item": "create:andesite_alloy"

View file

@ -15,7 +15,7 @@
"item": "create:shaft"
},
"A": {
"tag": "forge:ingots/brass"
"tag": "steampowered:bronze"
},
"C": {
"item": "steampowered:bronze_cogwheel"

View file

@ -7,13 +7,13 @@
],
"key": {
"S": {
"tag": "forge:ingots/brass"
"tag": "steampowered:bronze"
},
"C": {
"item": "create:andesite_alloy"
},
"D": {
"tag": "forge:plates/brass"
"tag": "steampowered:bronzeplate"
}
},
"result": {

View file

@ -7,10 +7,10 @@
],
"key": {
"P": {
"tag": "forge:plates/brass"
"tag": "steampowered:bronzeplate"
},
"B": {
"tag": "forge:ingots/brass"
"tag": "steampowered:bronze"
},
"I": [
{

View file

@ -0,0 +1,9 @@
{
"values": [
"#forge:ingots/brass",
{
"id":"#forge:ingots/bronze",
"required":false
}
]
}

View file

@ -0,0 +1,9 @@
{
"values": [
"#forge:plates/brass",
{
"id":"#forge:plates/bronze",
"required":false
}
]
}