Skip to content

Commit

Permalink
Fixed hasFacing serving basically no purpose in RedstoneMachine
Browse files Browse the repository at this point in the history
  • Loading branch information
fuj1n committed Oct 12, 2019
1 parent 98976e3 commit 78b4a2c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
2 changes: 0 additions & 2 deletions src/main/java/slimeknights/tmechworks/client/ClientProxy.java
Expand Up @@ -2,8 +2,6 @@

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import slimeknights.mantle.client.book.BookLoader;
import slimeknights.mantle.client.book.data.BookData;
import slimeknights.mantle.client.book.repository.FileRepository;
Expand Down
Expand Up @@ -48,9 +48,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

Expand All @@ -65,15 +63,20 @@ public abstract class RedstoneMachineBlock extends DirectionalBlock {
protected RedstoneMachineBlock(Material material) {
super(Block.Properties.create(material).hardnessAndResistance(3.5F));
this.setDefaultState(this.stateContainer.getBaseState()
.with(FACING, Direction.NORTH)
.with(HAS_DISGUISE, false)
.with(LIGHT_VALUE, 0));

if(hasFacingDirection()) {
this.setDefaultState(this.getDefaultState().with(FACING, Direction.NORTH));
}
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
super.fillStateContainer(builder);
builder.add(FACING);
if(hasFacingDirection()) {
builder.add(FACING);
}

// Disguise properties
builder.add(HAS_DISGUISE);
Expand Down Expand Up @@ -116,10 +119,11 @@ public boolean hasFacingDirection() {
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
if (!hasFacingDirection())
if (!hasFacingDirection()) {
return super.getStateForPlacement(context);
}

return this.getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite());
return super.getStateForPlacement(context).with(FACING, context.getNearestLookingDirection().getOpposite());
}

@Override
Expand Down
@@ -1,7 +1,7 @@
package slimeknights.tmechworks.common.blocks.tileentity;

import net.minecraft.block.BlockState;
import net.minecraft.client.resources.I18n;
import net.minecraft.block.DirectionalBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.entity.player.ServerPlayerEntity;
Expand All @@ -17,10 +17,8 @@
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.thread.EffectiveSide;
import slimeknights.mantle.tileentity.InventoryTileEntity;
Expand Down Expand Up @@ -66,27 +64,32 @@ public void updateRedstone() {
if (isFirstTick)
return;

Direction facing = getWorld().getBlockState(getPos()).get(RedstoneMachineBlock.FACING);
Direction facing = Direction.NORTH;

if (hasFacingDirection()) {
facing = getWorld().getBlockState(getPos()).get(RedstoneMachineBlock.FACING);
}

int oldPow = redstoneState;

Direction[] directions = Direction.values();
int maxPow = 0;

for(Direction dir : directions) {
if(dir != facing){
for (Direction dir : directions) {
if (!hasFacingDirection() || dir != facing) {
int pow = world.getRedstonePower(pos.offset(dir), dir);
if(pow > maxPow)
if (pow > maxPow)
maxPow = pow;
}
}

int downPow = world.getRedstonePower(pos, Direction.DOWN);
if(downPow > maxPow)
if (downPow > maxPow)
maxPow = downPow;

redstoneState = maxPow;

if(maxPow != oldPow) {
if (maxPow != oldPow) {
onRedstoneUpdate();
}
onBlockUpdate();
Expand All @@ -105,7 +108,8 @@ public void onRedstoneUpdate() {
/**
* Called when redstone state is updated, but the redstone state remains unchanged
*/
public void onBlockUpdate() {}
public void onBlockUpdate() {
}

/**
* @return The redstone power level
Expand Down Expand Up @@ -152,8 +156,8 @@ public void refreshDisguise() {
boolean hasDisguise = !item.isEmpty() && item.getItem() instanceof BlockItem;
state = state.with(RedstoneMachineBlock.HAS_DISGUISE, hasDisguise);

if(hasDisguise) {
BlockState disguiseState = ((BlockItem)item.getItem()).getBlock().getDefaultState();
if (hasDisguise) {
BlockState disguiseState = ((BlockItem) item.getItem()).getBlock().getDefaultState();

state = state.with(RedstoneMachineBlock.LIGHT_VALUE, Math.max(disguiseState.getBlock().getLightValue(disguiseState, getWorld(), getPos()), disguiseState.getBlock().getLightValue(disguiseState)));
}
Expand All @@ -169,7 +173,7 @@ public CompoundNBT writeItemData(CompoundNBT tags) {
tags.putInt("InventorySize", getSizeInventory());
writeInventoryToNBT(tags);

if(this.hasCustomName()) {
if (this.hasCustomName()) {
tags.putString("CustomName", ITextComponent.Serializer.toJson(this.inventoryTitle));
}

Expand All @@ -192,7 +196,7 @@ public CompoundNBT writeItemData(CompoundNBT tags) {
public void readItemData(CompoundNBT tags) {
super.read(tags);

if(tags.contains("Disguise")){
if (tags.contains("Disguise")) {
CompoundNBT itemNBT = tags.getCompound("Disguise");

ItemStack disguise = ItemStack.read(itemNBT);
Expand Down Expand Up @@ -221,7 +225,7 @@ public void read(CompoundNBT tags) {

@Override
public void writeInventoryToNBT(CompoundNBT tag) {
if(!isEmpty())
if (!isEmpty())
super.writeInventoryToNBT(tag);
}

Expand Down Expand Up @@ -266,7 +270,7 @@ public void sync() {
}

for (PlayerEntity player : world.getPlayers()) {
((ServerPlayerEntity)player).connection.sendPacket(packetUpdateTileEntity);
((ServerPlayerEntity) player).connection.sendPacket(packetUpdateTileEntity);
}
}
}
Expand All @@ -279,7 +283,7 @@ public ItemStack storeTileData(ItemStack stack) {

stack.setTagInfo("BlockEntityTag", tags);

if(this.hasCustomName()){
if (this.hasCustomName()) {
CompoundNBT name = new CompoundNBT();
name.putString("Name", ITextComponent.Serializer.toJson(inventoryTitle));

Expand All @@ -297,7 +301,7 @@ public IModelData getModelData() {

@Override
public void getInformation(@Nonnull List<ITextComponent> info, InformationType type, PlayerEntity player) {
if(type != InformationType.BODY)
if (type != InformationType.BODY)
return;

info.add(new TranslationTextComponent("tooltip.waila.power", getRedstoneState()));
Expand All @@ -313,4 +317,15 @@ public void getInformation(@Nonnull List<ITextComponent> info, InformationType t
public Container createMenu(int id, PlayerInventory playerInventory, PlayerEntity playerEntity) {
return new DisguiseContainer(id, playerInventory, this);
}

public final boolean hasFacingDirection() {
BlockState state = getBlockState();

if(state.getBlock() instanceof RedstoneMachineBlock)
{
return ((RedstoneMachineBlock)state.getBlock()).hasFacingDirection();
}

return state.has(DirectionalBlock.FACING);
}
}

0 comments on commit 78b4a2c

Please sign in to comment.